[R] Does split() preserve order?

Charles C. Berry cberry at tajo.ucsd.edu
Thu Aug 27 05:49:18 CEST 2009

On Wed, 26 Aug 2009, Alistair Gee wrote:

> If x is a vector (or data frame) that is in a particular order, and I
> call split(x, f) to partition x, will the elements of each partition
> remain in order?

They must for example( split ) to work as advertised, viz.

 	### Calculate z-scores by group

 	z <- unsplit(lapply(split(x, g), scale), g)



> That is, is the following assertion always TRUE?
> for(i in split(x, f)) {
>  stopifnot(!is.unsorted(i))
> }
> I suspect that this is the case, but the help page does not discuss
> preservation of order in the result of split().
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

More information about the R-help mailing list