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[[i]])/(length(foo)))) } Seems to work for an length with a even value of your unique values in your first column. But still a problem for odd lengths. Maybe solved by adding fake rows that you can remove afterwords (with a specific index for example). -- View this message in context: http://r.789695.n4.nabble.com/Sorting-data-frame-by-prepared-order-tp4704038p4704058.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.