[R] Are loops handled differently in newer versions of R?
mdrennie at gmail.com
Wed Mar 17 03:53:27 CET 2010
I'm perplexed- I have some code that uses for() loops that works fine in
R version 2.8 on my mac, worked fine in version 2.8 on my old windows
machine, but doesn't work in version 2.10 on windows.
The loop implements a function over a data frame (code is included below).
In Mac (running version 2.8), the results of the loop are what I expect:
 0.034939481 0.015743706 0.089287030 0.001098538 0.039290594
But in Windows (running version 2.10.1), I get a bunch of NA's...
A B C D E
NA NA NA NA NA
If I had to guess, I'd say that R v. 2.10 is handling the i in
lab8.dat[,1] differently, given that it's keeping the row names in the
output for p_unadj... but why would that stop it from applying the
Any thoughts or suggestions are welcome.
Here's the code...
#build the dataset
locn<-c("A", "B", "C", "D", "E")
n<-c(28, 14, 21, 52, 35)
corr.r<-c(0.40, 0.63, 0.38, 0.44, 0.35)
lab8.dat<-data.frame(locn, n, corr.r)
#write the function
#given a sample size (n) and correlation coefficient (r), returns the
probability for that test
probt<-2*(pt(t, df, lower.tail=FALSE))
#try out the function...
#write a loop to implement that function for every correlation in your
#all this just built an empty vector to store the results of our loop...
for ( i in lab8.dat[,1] )
#if executed on my Mac, running R v.2.8, this works (and did using 2.8
on my old windows machine). Running v. 2.10 in Windows, I get NAs.
Michael D. Rennie, Ph.D.
Postdoctoral Fellow, Environmental and Life Sciences Program
2140 East Bank Drive, DNA Building (2nd Floor)
Peterborough, Ontario K9J 7B8
More information about the R-help