[R] Suggestion for ?split

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Jun 22 08:51:50 CEST 2006


On Thu, 22 Jun 2006, Simon Blomberg wrote:

> Hi all,
>
> I noticed an undocumented feature for split. It sorts the resulting list
> according to the grouping factor. An example:
>
> test <- data.frame(x=rnorm(48), f=letters[sample(1:8)])
> split(test, test$f)
>
> I wasn't expecting this behaviour, although I was pleasantly surprised.
> I suggest that the help page for split be amended to include this
> feature. I know it's a small thing, but someone else may also find it
> useful to know.

It is not really true.  The help page says

      The value returned from 'split' is a list of vectors containing
      the values for the groups.  The components of the list are named
      by the _used_ factor levels given by 'f'.

They are in the same order as the _used_ factor levels (as the statement 
implies), but those are in no sense sorted.  Indeed, the factor may be 
created by as.factor or interaction, and working out the order of the 
factor levels can be tricky, which is why they are named.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list