Mark Heckmann
2010-Mar-21 01:09 UTC
[R] using a condition given as string in subset function - how?
Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100321/b8986e7a/attachment.pl>
jim holtman
2010-Mar-21 01:33 UTC
[R] using a condition given as string in subset function - how?
I know that if you have to resort to 'parse(text=...)', you should look for another way (it is a 'fortune'), but it is getting late, and at least it works:> eval(parse(text="subset(df, A==1 & B==1)"))A B 1 1 1 On Sat, Mar 20, 2010 at 9:09 PM, Mark Heckmann <mark.heckmann@gmx.de> wrote:> df <- data.frame(A=c(1,2), B=c(1,1)) > > I have a string containing a condition for a subset function, like: > conditionAsString <- paste(names(df), df[1,], sep="==", collapse=" & ") > > conditionAsString > > "A==1 & B==1" > > Now I want to use this string in the subset call, like > > subset(df, conditionAsString) > > I do not exactly now how to combine substitute, expression, parse and > so on to get what I want, which would be: > > subset(df, A==1 & B==1) > > but using the string conditionAsString. > > Thanks, > Mark > ––––––––––––––––––––––––––––––––––––––– > Mark Heckmann > Blog: www.markheckmann.de > R-Blog: http://ryouready.wordpress.com > > > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > 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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
Maybe Matching Threads
- evaluate variable within expression - how?
- Sweave problem on Mac OS when using umlauts and summary()
- all extended ASCII characters exist for R console output?
- latent class factor analysis (LCFA) in R?
- determine size (width and height) of a graphics file via R - how?