[R] Building a list
Noah Silverman
noah at smartmediacorp.com
Sun May 30 23:52:21 CEST 2010
Hello,
I need to build a "list of lists"
We have 20 groups we are generating MCMC samples for. There are 10
coefficients, and 10000 MCMC iterations.
I would like to store each iteration by-group in a list. My problem is
with the first iteration.
Here is a toy example:
Chain <- list()
for (j in 1:10000){
coef <- c(1,2,3,4,5,6,7,8,9,10) #would be actual MCMC samples
Chain[[j]] <- rbind(Chain[[j]], coef)
}
This returns an error, UNLESS I initialize the first row of Chain[[j]]
with something.
The idea is that for any group, I can quickly extract, plot, average,
etc the values for each coefficient.
for example:
Chain[[5]][,3] will give me all 10,000 values of coefficient 3 for group
5.
Again, this seems to work, but I can't initialize the chain with a
random value as it will cause problems with the data summary later.
(Each row in Chain[[j]] will be out of sync by 1, subsequently all
summary and plotting work will have to account for this - it can get
messy in a large program.)
Is there an easier way to do this? Am I missing something?
More information about the R-help
mailing list