Converting a list to a data frame
Thanks for the tips -----Original Message----- From: Rui Barradas <ruipbarradas at sapo.pt> Sent: Saturday, July 24, 2021 11:40 AM To: reichmanj at sbcglobal.net; R-help at r-project.org Subject: Re: [R] Converting a list to a data frame Hello, This should do it: as.data.frame(weight_chains$mcmc) The only list member already has a dim attribute of length 2 and dimnames' 2nd member are the colnames, just coerce to df. Hope this helps, Rui Barradas ?s 14:18 de 24/07/21, Jeff Reichman escreveu:
How does one convert a list into a data frame?
str(weight_chains)
List of 1 $ : 'mcmc' num [1:100000, 1:3] -105 -105 -105 -104 -103 ... ..- attr(*, "dimnames")=List of 2 .. ..$ : NULL .. ..$ : chr [1:3] "a" "b" "s" ..- attr(*, "mcpar")= num [1:3] 1001 101000 1 - attr(*, "class")= chr "mcmc.list" Such that ..
weight_chains
a b s
1 -104.72512 1.0141407 9.369227
2 -104.52297 1.0167432 9.131354
3 -104.72669 1.0139528 9.219877
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.