From romain.francois at dbmail.com  Wed Dec 16 08:03:33 2009
From: romain.francois at dbmail.com (Romain Francois)
Date: Wed, 16 Dec 2009 08:03:33 +0100
Subject: [Rd] split.data.frame
In-Reply-To: <4B281850.6000708@biostat.ku.dk>
References: <4B27518E.6030209@dbmail.com> <4B281850.6000708@biostat.ku.dk>
Message-ID: <4B288645.3010602@dbmail.com>

On 12/16/2009 12:14 AM, Peter Dalgaard wrote:
> 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()

Sure, this is just about convenience and laziness.

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

this still works

> - 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?

this is a problem indeed.

thanks for the reply.

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/HlX9 : new package : bibtex
|- http://tr.im/Gq7i : ohloh
`- http://tr.im/FtUu : new package : highlight



[Rd] split.data.frame
Romain Francois