[R] Help with loops and how R stores data

R-novice sam.the.baker at hotmail.com
Sat Feb 2 22:16:41 CET 2008


I am trying to make an array c(3,8) that contains the averages of what is in
another array c(9,8).  I want to average rows 1:3, 4:6, 7:9 and have a loop
replace the generic 1:24 values in my array with the average of the three
rows.  

The problem I am having is that R only replaces the last value from the
loops, and I am not experienced enough with R to know how it stores data
when looping and how to overcome this problem. By having it print the avg, I
was expecting to see 24 numbers, but it only gives me one. 

Here is my code.

cts.sds<-array(1:24,c(3,8))
for(i in 3){
  for(j in 8){
    avg<-sum(exprdata[3*i-2:3*i,j]/3)
    cts.sds[i,j]<-avg
    print(avg)
  }
}
print(cts.sds)

Any help with this pesky matter will be greatly appreciated.  
-- 
View this message in context: http://www.nabble.com/Help-with-loops-and-how-R-stores-data-tp15247392p15247392.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list