[R] problems with assign

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


Hello.

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

I read them with the following commands:

list=scan(file="list",what=list(nom=""))
# in the file list, I have all the filenames.
n=length(list[[1]])

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:

assign("aux2[1,1]",as.matrix(read.table(list[[1]][1]))[1,1])

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

Thanks,

Arnau.




More information about the R-help mailing list