I just wondering if I can be sure that split() is always sorting the results?
What is the rule for the sorting?
The example works, but I haven’t found the according line in the help pages. Sorry if I misread the help.
dat.exmpl <- data.frame(cbind(a=11:20, b=rep(3,10)), fac = c(2,1))
split(dat.exmpl, dat.exmpl$fac)
dat.exmpl <- data.frame(cbind(a=11:20, b=rep(3,10)), fac=rep(c("blueb","bluea")))
split(dat.exmpl, dat.exmpl$fac)
ExtraQ: Is there a way to remain the order which is supplied?
The sort order of
splitis the factor order of your grouping variable. So, if your grouping variable is a factor, then the levels of that factor are kept intact.An example: modify your data so that
fachas the levelsc("blueb","bluea"):Then the results of
splitare in the same order as the levels offac: