[R] subset arg in (modified) evalq

Gabor Grothendieck ggrothendieck at gmail.com
Fri May 18 17:18:30 CEST 2007


Try this:

e <- quote(summary(y + z))
all.vars(e)


On 5/18/07, Vadim Ogranovich <vogranovich at jumptrading.com> wrote:
> Sorry, I didn't explain myself clear enough. I knew about the select arg in
> subset(). My question was, given the expression expression(summary(x+y)),
> how to extract all names that will be looked up during its evaluation.
>
> As to checking performance assumptions, you are right, in most cases the
> overhead is negligible, but sometimes I work with really big data sets.
>
> Thanks a lot for your help,
> Vadim
>
>
> ----- Original Message -----
> From: "Gabor Grothendieck" <ggrothendieck at gmail.com>
> To: "Vadim Ogranovich" <vogranovich at jumptrading.com>
> Cc: r-help at stat.math.ethz.ch
> Sent: Friday, May 18, 2007 9:53:26 AM (GMT-0600) America/Chicago
> Subject: Re: [R] subset arg in (modified) evalq
>
> I would check your performance assumption with an actual test before
> concluding such but at any rate subset does have a select argument. See
> ?subset
>
> On 5/18/07, Vadim Ogranovich <vogranovich at jumptrading.com> wrote:
> > Thanks Gabor!  This does exactly what I wanted.
> >
> > One follow-up question, how to extract the var names, in this case y, z,
> > from the expression? The subset function creates a new object and this may
> > be expensive when the data has a lot of irrelevant collumns. So I thougth
> > that I could reduce this to the columns I actually need.
> >
> > Thanks,
> > Vadim
> >
> >
> >
> > ----- Original Message -----
> > From: "Gabor Grothendieck" <ggrothendieck at gmail.com>
> > To: "Vadim Ogranovich" <vogranovich at jumptrading.com>
> > Cc: r-help at stat.math.ethz.ch
> > Sent: Friday, May 18, 2007 9:19:49 AM (GMT-0600) America/Chicago
> > Subject: Re: [R] subset arg in (modified) evalq
> >
> > Try this:
> >
> >    with(subset(data, x > 0), summary(y + z))
> >
> >
> > On 5/18/07, Vadim Ogranovich <vogranovich at jumptrading.com> wrote:
> > > Hi,
> > >
> > > When using evalq to evaluate expressions within a say data.frame context
> I
> > often wish there was a 'subset' argument, much like in lm() or any ather
> > advanced regression model. I would be grateful for a tip how to do this.
> > >
> > > Here is an illustration of what I want:
> > >
> > > n <- 100
> > > data <- data.frame(x=rnorm(n), y=rnorm(y), z=rnorm(z))
> > >
> > > # this works
> > > evalq({ i <- 0<x; summary(y[i] + z[i]) }, data)
> > >
> > > # I want to do the above w/o explicit subscripting, e.g.
> > > myevalq(summary(y + z), subset=0<x, data)
> > >
> > > Thanks,
> > > Vadim
> > >
> > >        [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> >
>



More information about the R-help mailing list