Dear all, I have following list object: dat <- vector("list", length=4) for(i in 1:4) dat[[i]] <- diag(rnorm(5)^2) names(dat) <- paste("A", 1:4, sep="") It is ok upto this point. However if I want apply, suppose chol() function on any of it's element, I am getting error:> chol(dat['A1'])Error in chol.default(dat["A1"]) : non-numeric argument to 'chol' Can somebody point me where I am doing wrong? Thanks and regards,
On 2010-09-19 4:21, Christofer Bogaso wrote:> Dear all, I have following list object: > > dat<- vector("list", length=4) > for(i in 1:4) dat[[i]]<- diag(rnorm(5)^2) > names(dat)<- paste("A", 1:4, sep="") > > It is ok upto this point. However if I want apply, suppose chol() > function on any of it's element, I am getting error: > >> chol(dat['A1']) > Error in chol.default(dat["A1"]) : non-numeric argument to 'chol' > > Can somebody point me where I am doing wrong?You need another set of brackets: chol(dat[['A1']]) -Peter Ehlers