how to get an element with same name in a list to avoid for loop in R -
i have simple question. assuming have list obj of length 500
obj[[1]], obj[[2]], ....obj[[500]], #for each obj[[i]], has element obj[[i]]$logl,
my question how extract logl of each obj avoid loop this?
logl = rep(na, length(obj)) for(i in 1: length(obj)){ logl[i] = obj[[i]]$logl }
is there way sapply or advanced packages plyr? open solutions long faster loop since need within mcmc , length of list can 3000 prefer fast method.
thanks in advance!
you can use apply group of functions purpose. here tutorial http://www.r-bloggers.com/using-apply-sapply-lapply-in-r/
sapply(obj, function(x) x$logl )
Comments
Post a Comment