[R] inconsistent output when using variable substitution

Robert Felty robfelty at indiana.edu
Sat May 31 00:31:48 CEST 2008


Duncan, Mark, et al.,
> It's a scoping problem.  To be helpful, subset looks up variables within
> the dataframe first.  Since it can find Subj there, that's the one it
> uses in the test.
>
> The easiest solution is just to make sure that Subj is named something
> that isn't a column of Trials, e.g. localSubj.  Then you could use
>
> subset(Trials, Subj == localSubj[1])

This works perfectly, as does 

> thisSubj <- Trials[Trials$Subj == Subj[1], ]

I had tried the latter method awhile ago when I was first learning, but I had 
been missing the final comma, and had come to the conclusion that this method 
only worked when selecting a particular column of a data frame. Now I know 
better. Thanks so much for everyone's help. I am very impressed by the R 
community!!!!

Rob

--
Robert Felty
http://robfelty.com

"nunc est bibendum" 
  -- Horace, Ode 37



More information about the R-help mailing list