[R] inconsistent output when using variable substitution

From: Robert Felty <robfelty_at_indiana.edu>
Date: Fri, 30 May 2008 15:59:22 -0400

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.


Robert Felty

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

R-help_at_r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 02 Jun 2008 - 04:19:16 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 02 Jun 2008 - 04:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive