Works great. I did a couple changes so as to not affect the original
data.frame (and had to add levels back b/c I removed them in the original
read.csv).
a <- data.frame(V1=letters[rep(4:1,2)], V2=1001:1008)
b <- a
levels(b) <- unique(a$V1)
b$V1 <- factor(b$V1,levels=c('c','d','a','b'))
a.sorted
Set the levels of the factor a$V1 to the order
in which you want them to be sorted. E.g.,
> a <- data.frame(V1=letters[rep(4:1,2)], V2=1001:1008)
> a[do.call(order,a[c('V1','V2')]),]
V1 V2
4 a 1004
8 a 1008
3 b 1003
7 b 1007
2 c 1002
6 c 1006
1 d 1001
5 d 1005
2 matches
Mail list logo