Maybe someone here with more expirience with mcmc objects can help me out.
Problem: I have a list with 20+ mcmc objects stored. I need to assign variable names for each of the mcmc object.
I have another list with all the variables names for each mcmc stored (as columns in dataframes).
I can do this individually, using the "varnames" function from the coda package, like this:
Being "votes" my dataframe list and "posterior" my mcmc object list..
names <- votes[[1]]$legis # extracts the names variable for the first dataframe on the list.
varnames(posterior[[1]]) <- names # assings the extracted names as variable names fo the first mcmc object on the list.
However, rather than doing this one by one, I would like to do it all at once. I've tried the following code...
p2 <- lapply(posterior, function(x)varnames(posterior[[x]]) <- names)
But i get Error in *tmp*[[x]] : Recursive indexing failed at level 2
. I've tried some variations of that line, but I'm having a hard time understanding how to properly index this, or how to do what I want to do at all.
I know its kind of an specific problem, but maybe someone here can give me a hint or something.
Thanks in advance for the help. Sorry I can't provide some data, but it's kinda difficult to get workable samples of this.
Regards, Federico