[Rd] split.data.frame

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Dec 16 00:14:24 CET 2009


Romain Francois wrote:
> Hello,
> 
> I very much enjoy "with" and "subset" semantics for data frames and was 
> wondering if we could have something similar with split, basically by 
> evaluating the second argument "with" the data frame :

I seem to recall that this idea was considered and rejected when the 
current split.data.frame was written (10 years ago!). The main reasons 
were that

- it's not really THAT hard to evaluate a single splitting expression 
using with() or eval()

- not all applications will have the splitting factor inside the df to 
split ( split(df[-1], df[[1]]) for a simple case)

- if you need a computed splitting factor, there's a risk of inadvertent 
variable capture. I.e., if you inside a function do

   ....
   grp <- ...whatever...
   spl <- split(x, grp)
   ....

and x has a variable called grp, what do you get?





-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-devel mailing list