Paste logical conditions in R
I have now rewriten my problem to make it clearer
I want to replace a condition like this where var is a variable in dataframe (dataframe$var) with a paste or other solution as I do have so many condition values(?) (a, b and c in my example).
I have tried to make a list(?) of the condtion values.
And to then use paste to make the logical condition
But that doesn't work
Help please =)
> fortune(106) If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005)
So I would encourage you to rethink what you're trying to do...
I would guess that you could use match or %in% to achieve your desired result, but you haven't told us what you're trying to do.
> sample <- c("a","b","c") > var <- c("a","d","c") > eval(parse(text=paste("var==",sample,"",sep="'",collapse="|")))  TRUE FALSE TRUE > var %in% sample  TRUE FALSE TRUE