r - Nested data frame -
i have got technical problem which, seems, not able solve myself. ran estimation mcmcglmm package. results$sol access estimated posterior distributions. applying class() tells me object of class "mcmc". using as.data.frame() results in nested data frame contains other data frames (one data frame contains many other data frames). rbind() data frames within main data frame in order produce 1 data frame (or rather vector) values of posterior distributions , name of (secondary) data frame rowname., ideas? grateful every hint!
update: didn't manage produce useful data set purpose of stackoverflow, these sampling chains these data sets large. if want me, please consider run following (exemplaric) model
require(mcmcglmm) data(plodiapo) result <- mcmcglmm(po ~ plate + fsfamily, data = plodiapo, nitt = 50, thin = 2, burn = 10, verbose = false)
result$sol (an mcmc object) chains stored. want rbind chains in order have vector values of posterior distributions , variable names rownames (or since no duplicated rownames allowed, additional character vector).
i can't (using example code mcmcglmm) construct example as.data.frame(model$sol) gives me dataframe of dataframes. although there's simple answer can't check easily.
that said, here's example might help. note if child dataframes don't have same colnames won't work.
# create nested data.frame example work on a.df <- data.frame(c1=runif(10),c2=runif(10)) b.df <- data.frame(c1=runif(10),c2=runif(10)) full.df <- data.frame(1:10) full.df$a <- a.df full.df$b <- b.df full.df <- full.df[,c("a","b")] # solution res <- do.call(rbind,full.df)
edit
okay, using new example,
require(mcmcglmm) data(plodiapo) result<- mcmcglmm(po ~ plate + fsfamily, data=plodiapo,nitt=50,thin=2,burn=10,verbose=false) melt(do.call(rbind,(as.data.frame(result$sol))))
Comments
Post a Comment