Try this: my.array <- replicate(10, data.frame(matrix(sample(9), 3)), simplify = FALSE)
#2 lapply(my.array, replace, list = 3, values = newThirdColumn) The solution was for matrices, the above works with data.frames. On Thu, Sep 3, 2009 at 5:03 PM, Carlos Hernandez <carlos.u...@gmail.com>wrote: > > On Thu, Sep 3, 2009 at 4:34 PM, Henrique Dallazuanna <www...@gmail.com>wrote: > >> Try this: >> >> #1 >> lapply(my.array, '[', , 3) >> >> > this works! thank you a lot! > > >> #2 >> newThirdColumn <- sample(3) >> lapply(my.array, replace, list = 7:9, values = newThirdColumn) >> >> > i did not understand this last line, so far i couldn't make it work. > > would it be easier to replace the values (the third column of each matrix > in my.array) using an array like in #1? > > thank you for your reply! > > >> On Thu, Sep 3, 2009 at 11:16 AM, Carlos Hernandez >> <carlos.u...@gmail.com>wrote: >> >>> Dear All, >>> I created a list (of length Z) in the following way: >>> >>> my.array <- vector("list", Z) >>> >>> then i assigned a matrix (of T rows by N columns) in each of the elements >>> of >>> the list my.array in the following way: >>> >>> my.array[[i]] <- matrix.data ##( matrix.data has dimensions TxN, and i >>> repeated this command for i from 1 to Z, the matrix.data contains only >>> numeric data) >>> >>> and >>> 1. i would like to extract all the third columns of each of the Z >>> matrices >>> stored in my.array (such that i get a new list only with the 3rd columns >>> of >>> each matrix in the elements of a new list) >>> >>> 2. i would like to know how could i replace all the 3rd columns of each >>> matrix in my.array if i have a second matrix (size ZxT) with these >>> columns. >>> >>> is there a simple way to do these tasks? i appreciate any hints or >>> advice. >>> >>> Carlos >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> >> >> -- >> Henrique Dallazuanna >> Curitiba-Paraná-Brasil >> 25° 25' 40" S 49° 16' 22" O >> > > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.