a loop to chang data matrix name
Yu-Ling Wu <yuling5 at yahoo.com> writes:
Hi,
I have 50 data matrix x1 ~ x5. I want to write a loop
to check the number of
rows for each data matrix. How to make the data matrix
name (numerical part)
increase by 1 each time it loops?
That is,
loop1: nrow(x1)
loop2: nrow(x2)
....
loop50: nrow(x50)
---------------------------------------------------------------
for (i in 1:50) {
if nrow( xi ) > 20 <=== how to make this work?
do someting ......
}
--------------------------------------------------------------
With a bit more experience, you could probably ensure that your
matrices were in a list to begin with instead of having information
encoded in their name, but try
for (xi in paste("x",1:50,sep="") {
if (nrow( get(xi) ) > 20 )
do someting ......
}
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._