也许这里有更多关于mcmc对象的经验的人可以帮助我。
问题:我有一个存储了20+ mcmc对象的列表。我需要为每个mcmc对象指定变量名。
我有另一个列表,其中存储了每个mcmc的所有变量名(作为dataframe中的列)。
我可以使用coda包中的"varnames“函数单独完成此操作,如下所示:
“投票”我的数据帧列表和“后面”我的mcmc对象列表..
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.然而,与其逐一做这件事,我更愿意一次做完所有的事情。我试过下面的代码...
p2 <- lapply(posterior, function(x)varnames(posterior[[x]]) <- names)但我得到了Error in *tmp*[[x]] : Recursive indexing failed at level 2。我已经尝试了这一行的一些变体,但我很难理解如何正确地索引这行代码,或者如何做我想做的事情。
我知道这是一种特定的问题,但也许这里有人可以给我一个提示或其他什么。
提前感谢你的帮助。很抱歉,我不能提供一些数据,但这是有点困难,以获得可行的样本。
问候你,费德里科
发布于 2013-03-07 10:03:52
你不需要做任何lapply。
试试names(posterior) <- votes[[1]]$legis
https://stackoverflow.com/questions/15261705
复制相似问题