Re: [R] Sorting data frame by prepared order

2015-03-02 Thread JS Huang
Here is an implementation. > t <- > data.frame(x=c(1,1,1,1,1,2,2,2,2,2),y=c("a","a","a","b","b","a","a","b","b","b")) > t x y 1 1 a 2 1 a 3 1 a 4 1 b 5 1 b 6 2 a 7 2 a 8 2 b 9 2 b 10 2 b > assignSeq function(test) { temp <- test[order(test$x),] InC <- numeric(length(test)) inD <-

Re: [R] Sorting data frame by prepared order

2015-03-02 Thread jeff6868
Hi, Maybe a beginning of solution with this? test <- data.frame(x=c(1,1,1,1,1,1,2,2,2,2,2,2),y=c("a","a","a","b","b","b","a","a","b","b","b","a")) test[order(test$x),] out <- split(test,test$x) for (i in 1:length(out)) { foo <- unique(out[[i]][,2]) out[[i]][,2] <- rep(foo,(nrow(out[[