Re: [R] Sorting Data Frames in R by multiple columns with a custom order

2013-11-07 Thread arun
If you already have the order stored in a list or so: For example: dat1 <- as.data.frame(mat,stringsAsFactors=FALSE) lst1 <- list(c("OF","ON"), c("US","UK", "WW","BO","BR","CA"), c("P2","P3","P1"),c("S2","S1","S3"))  dat1[] <- lapply(seq_along(lst1),function(i) factor(dat1[,i],levels=lst1[[i]]))

Re: [R] Sorting Data Frames in R by multiple columns with a custom order

2013-11-07 Thread arun
Hi, Not sure whether this helps: dat1 <- as.data.frame(mat,stringsAsFactors=FALSE) dat1$c4 <- factor(dat1$c4,levels=c("OF","ON"))  dat1$c1 <- factor(dat1$c1,levels=c("US","UK","WW","BO","BR","CA"))  dat1$c2 <- factor(dat1$c2, levels=c("P2","P3","P1"))  dat1$c3 <- factor(dat1$c3, levels=c("S2","S1"