[R] create an object list in a loop

John Fox jfox at mcmaster.ca
Mon Oct 28 15:37:44 CET 2002

Dear Allesandro,

At 12:38 PM 10/28/2002 +0100, AlessandroSemeria at cramont.it wrote:
>Hi! Probably I perform this question because I did'nt  still understand the
>  I have to build  many matrix, with different dimensions, and  I would to
>assign them a
>same 'prefix' name, i.e. "aval", but, obviuosly different suffix, something
>for (i in 1:n) {
>      aval%i% <- matrix(scan(data....),nrow=nr[i],ncol=nc[i]
>           }
>where "%i%" is a  symbol to indicate different label for different index i.
>Ther'is some trick to "paste" a label(i)  and to build the object aval%i%
>or some other way
>to perform my task?
>Thanks in advance for your help!

You can use paste() within assign() to compose the variable names:

         assign(paste("aval", i, sep=""), 

(I'm not sure what it is you're assigning to each of these variables, but I 
assume that it makes sense.)

I hope that this helps,
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox

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

More information about the R-help mailing list