This seems very similar to the data.table package.
The 'by' argument splits the data.table by that value then executes the j
expression within each subset. The package documentation talks about
'subset' and 'with' in some detail. See ?"[.data.table".
dt = data.table(x=1:20, y=rep(1:4,each=5)
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 tha
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
I agree, I would definitely appreciate that.
A simpler implementation:
split.data.frame <- function(x, f, drop = FALSE, ...)
{
ff <- eval(substitute(f), x, parent.frame())
lapply(split(seq_len(nrow(x)), ff, drop = drop, ...),
function(ind) x[ind, , drop = FALSE])
}
df <- data.frame(x =
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 :
split.data.frame
function(x, f, drop = FALSE, ...){
call <- match.call( )