> -----Original Message-----
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Christof Kluß
> Sent: Thursday, January 05, 2012 8:04 AM
> Cc: r-h...@stat.math.ethz.ch
> Subject: Re: [R] selection part of "subset"
> 
> Hi
> 
> the output should look like     r <- subset(tab, a==v)
> but now I have something like   r <- subset(tab, "a"==v)
> and                             r <- subset(tab, [["a"]]==v)
> does not work :(
> 
> greetings
> Christof
> 
> Am 05-01-2012 16:51, schrieb Christof Kluß:
> > Hi
> >
> > I want to do something like
> >
> > a <- c(10,20,15,43,76,41,25,46)
> > tab <- data.frame(a)
> >
> > name <- "a"
> >
> > for (v in unique(tab[[name]])) {
> >   r <- subset(tab, name==v)   # this does not work
> >   ...
> > }
> >
> > i.e. a "string" on the left side of the select expression (subset).
> How
> > could I solve this?


Christof,

Maybe you could look at ?get.  However, even using get(), you code probably 
won't work.  get(name) will return a vector, and v in your example is a scalar. 
  What is the task you are trying to accomplish?


Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


______________________________________________
R-help@r-project.org 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.

Reply via email to