[R] How to translate string to variable inside a command in an easy way in R

Sarah Goslee sarah.goslee at gmail.com
Wed Jul 13 14:28:22 CEST 2011


Hi,

On Wed, Jul 13, 2011 at 7:03 AM, UriB <uriblass at gmail.com> wrote:
> Greg Snow-2 wrote:
> "You are suffering from the fact that the longest distance between 2 points
> is a shortcut.
>
> The df$column notation is a shortcut for df[[column]] that has some nice
> properties, but the shortcut gets in the way when you want to do something
> more structured.  Try qq1[[z]]==y and avoid all that pasting, parsing, and
> evaluating. "
>
>
> My response:
> Unfortunately I find it to be not correct and unfortunately I see no way to
> avoid pasting parsing and evaluating in order
> to have functions that does simple things in R.
>
> temp<-qq1[qq1$PrimaryConditionGroup=="AMI",]
> has no error when
> temp<-qq1[qq1[[PrimaryConditionGroup]]=="AMI",] cause the following error
> announcement
>
> "Error in (function(x, i, exact) if (is.matrix(i)) as.matrix(x)[[i]] else
> .subset2(x,  :
>  object 'PrimaryConditionGroup' not found"


Because it should be:
temp<-qq1[qq1[["PrimaryConditionGroup"]]=="AMI",]

PrimaryConditionGroup is a column name, not an R object.


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list