[R] matrix of matrices

Federico Abascal fabascal at cnb.uam.es
Thu Feb 1 12:56:59 CET 2007


Dear all,

it is likely a stupid question but I cannot solve it.

I want to have a matrix of 100 elements.
Each element must be a vector of 500 elements.

If I do:
    imp<-array(dim=100)
    imp[1]<-vector(length=500)
it does not work. Warning message: "number of items to replace is not a
multiple of replacement length"

If I do:
    imp <- array(dim=c(100,500))   
and then fill imp:
    for(i in c(1:500)) {
        imp[i,] <- im[1:500,]
        #im[1:500,] is a vector of length 500, of class numeric. IT
CONTAINS NAMES!
    }

Now it works, but I loose the labels (names) associated to the original
"im" variable.
If I just do:
    j<- im[1:500,]
I do not loose the labels.

names(j) => list of labels
names(imp[1,]) => NULL

Any clue?

Thanks in advance!
Federico



More information about the R-help mailing list