[R] inconsistent output when using variable substitution

Robert Felty robfelty at indiana.edu
Fri May 30 21:59:22 CEST 2008


I am extremely puzzled by this behavior in R. I have a data frame called 
Trials in which I have results from an experiment. I am trying to do a 
subjects analysis, but getting weird results. Each row has 1 trial in it, 
which includes a column for the subject number I get the list of subject 
numbers like so:
> Subj=unique(sort(Trials$Subj))
Then I loop over them. But I get strange results. As a test, I tried the 
following:
> i=1
> Subj[i]
[1] 49
> thisSubj = subset(Trials,Trials$Subj==Subj[i])
> thisSubj$Ansr[1]
[1] "abacus"
> thisSubj = subset(Trials,Trials$Subj==49)
> thisSubj$Ansr[1]
[1] "able"

I am expecting to get a result of "able" both times, since I know that Subj[i] 
is 49, when i=1. Clearly the two different "thisSubj=..." lines are not 
returning the same values, as I would expect them to.

Is this the normal and correct behavior for R, or am I missing something? And 
if it is normal and correct, what do I need to do to get the behavior I am 
expecting.

Thanks in advance for any advice.

Rob
--
Robert Felty
http://robfelty.com

"In this house we obey the laws of thermodynamics!"
  -- Homer Simpson



More information about the R-help mailing list