[R] create an object list in a loop

Achim Zeileis zeileis at ci.tuwien.ac.at
Mon Oct 28 14:26:05 CET 2002


AlessandroSemeria at cramont.it wrote:
> 
> Hi! Probably I perform this question because I did'nt  still understand the
> R-philosophy.
>  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
> like:
> for (i in 1:n) {
>      aval%i% <- matrix(scan(data....),nrow=nr[i],ncol=nc[i]
> ...
>           }

You can do something like

for (i in 1:n) {
    assign(paste("aval", i, sep = ""), matrix(..., nrow = nr[i], ncol =
nc[i]))
}

Z


> 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!
> --------------------------
> Sincerely yours.
> Dr. Alessandro Semeria
> Models and Simulation Lab of
> The Environment Research Center - Montecatini (Edison Group),
> Via Ciro Menotti 48,
> 48023 Marina di Ravenna (RA), Italy
> Tel. +39 544 536811
> Fax. +39 544 538663
> E-mail: asemeria at cramont.it
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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