An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101221/2b18680d/attachment.pl>
matrix indexing in 'for' loop?
2 messages · govindas at msu.edu, Tom Gottfried
Hi Maha,
note that factors in your example is a character vector. So y is too. And then you try to retrieve
the values in your matrix from y...
You could put your matrices in a list and then use list-indexing in your outer loop:
ts.m.dmi <- matrix(c(1:20), 4, 5)
ts.m.soi <- matrix(c(21:40), 4, 5)
ts.m.pe <- matrix(c(21:40), 4, 5)
factors <- list(ts.m.dmi, ts.m.soi)
for (j in 0:1){
y <- factors[[j+1]]
for (i in 1:5){
cor.pe.y <- cor(ts.m.pe[,2], y[,i])
ct.tst <- cor.test(ts.m.pe[,2], y[,i])
}
}
Tom
Technische Universit?t M?nchen Department f?r Pflanzenwissenschaften Lehrstuhl f?r Gr?nlandlehre Alte Akademie 12 85350 Freising / Germany Phone: ++49 (0)8161 715324 Fax: ++49 (0)8161 713243 email: tom.gottfried at wzw.tum.de http://www.wzw.tum.de/gruenland