[R] problems with assign

Arnau Mir arnau.mir at uib.es
Tue Apr 11 20:30:57 CEST 2006


I have n files in a directory: file1, ..., filen.

I read them with the following commands:

# in the file list, I have all the filenames.

for (i in 1:n){
    aux <- paste("p",i,sep="")
    assign(aux, as.matrix(read.table(list[[1]][i])))

R creates the matrices p1,p2,...,pn.

I want to manipulate the matrices p1,...,pn and create new matrices
pp1,...,ppn. The dimensions of matrices ppi must be 100x100.
So, I do the following:

for (i in 1:n){
     aux2 <- paste("pp",i,sep="")
     assign(aux2, array(0,dim=c(100,100)))

My question is the following:

I want to assign to the matrix ppi[1,1] the value of pi[1,1] for i=1,...,n.
How can I do it?

For i=1, I try:


but it doesn't work because if I ask R:
R responses 0 but the value of p1[1,1] is not 0.



More information about the R-help mailing list