I still haven't come up with a solution to the question below, and I have
another one. I frequently find myself in a situation where I have the list
of columns I want to aggregate over in the form of a vector of strings, and
I have to do something like the following:
dat[, list(mean.z = mean(z)),
I've been using this setup:
> flist <- expression( list(mean.z = mean(z), sd.z = sd(z)) )
> dat[ , eval(flist), list(x)]
It works great, but there's one small catch. If I do something like
> flist <- expression(list(x.per.y = sum(x) / sum(y)))
> dat[, eval(flist), list(y)]
it does the wrong thi
ugust 8, 2012 9:17 AM
Subject: Re: [R] Repeated Aggregation with data.table
On Aug 7, 2012, at 9:28 PM, arun wrote:
> HI,
>
> Try this:
>
> fun1<-function(x,.expr){
> .expr<-expression(list(mean.z=mean(z),sd.z=sd(z)))
> z1<-eval(.expr)
> }
>
> #or
>
On Aug 7, 2012, at 9:28 PM, arun wrote:
HI,
Try this:
fun1<-function(x,.expr){
.expr<-expression(list(mean.z=mean(z),sd.z=sd(z)))
z1<-eval(.expr)
}
#or
fun1<-function(x,.expr){
.expr<-expression(list(mean.z=mean(z),sd.z=sd(z)))
z1<-.expr
}
dat[,eval(z1),list(x)]
dat[,eval(z1),list
HI,
Try this:
fun1<-function(x,.expr){
.expr<-expression(list(mean.z=mean(z),sd.z=sd(z)))
z1<-eval(.expr)
}
#or
fun1<-function(x,.expr){
.expr<-expression(list(mean.z=mean(z),sd.z=sd(z)))
z1<-.expr
}
dat[,eval(z1),list(x)]
dat[,eval(z1),list(y)]
dat[,eval(z1),list(x,y)]
A.K.
-
On Tue, Aug 7, 2012 at 4:36 PM, Elliot Joel Bernstein
wrote:
> I have been using ddply to do aggregation, and I frequently define a
> single aggregation function that I use to aggregate over different
> groups. For example,
>
> require(plyr)
>
> dat <- data.frame(x = sample(3, 100, replace=TRUE),
6 matches
Mail list logo