Dear All I want to store matrix in an array Suppose s<-array(0,4) for(i in 1:4) s[i] <- read_matrix(a,2,2) But the error - number of items to replace is not a multiple of replacement length. Can you suggest me any alternative method for storing a matrix in an array. Thanks In advance. Kind Regards Wesley C Mathew [[alternative HTML version deleted]]
On Mon, 27 Sep 2010 11:12:26 +0100 wesley mathew <wesleycmathew at gmail.com> wrote:> Dear All > > I want to store matrix in an array > Suppose s<-array(0,4) > for(i in 1:4) > s[i] <- read_matrix(a,2,2) > But the error - number of items to replace is not a multiple of > replacement > length. > Can you suggest me any alternative method for storing a matrix in an > array. > Thanks In advance. > Kind Regards > Wesley C Mathew >Wesley, I don't know what your read_matrix() function is doing. What you made is a 1-dimensional array of 4 elements. If your read_matrix() function returns more than one element per call, that is the source of your error message. It means you tried to store something in s[] that goes beyond its dimensions. Edwin> ______________________________________________ > R-help at 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.-- Dr. Edwin Groot, postdoctoral associate AG Laux Institut fuer Biologie III Schaenzlestr. 1 79104 Freiburg, Deutschland +49 761-2032945
Hi Wesley, Try this (untested): s <- array(0, dim = c(2, 2, 4)) for(i in 1:4) s[, ,i] <- read_matrix(a, 2, 2) Another (untested) option wold be s0 <- lapply(1:4, function(i) read_matrix(a, 2, 2)) s0 HTH, Jorge On Mon, Sep 27, 2010 at 6:12 AM, wesley mathew <> wrote:> Dear All > > I want to store matrix in an array > Suppose s<-array(0,4) > for(i in 1:4) > s[i] <- read_matrix(a,2,2) > But the error - number of items to replace is not a multiple of replacement > length. > Can you suggest me any alternative method for storing a matrix in an array. > Thanks In advance. > Kind Regards > Wesley C Mathew > > [[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. >[[alternative HTML version deleted]]