[R] Converting a list to a data frame

Jeff Reichman re|chm@nj @end|ng |rom @bcg|ob@|@net
Sat Jul 24 23:31:22 CEST 2021


Duncan

I need to plot the results (ggplot2) and I'm thinking I can only use a data.frame object in ggplot2. It is a rath r large "list" over 1 million rows. It is possible to work with a matrix in ggplot2?

Jeff

-----Original Message-----
From: Duncan Murdoch <murdoch.duncan using gmail.com> 
Sent: Saturday, July 24, 2021 12:03 PM
To: reichmanj using sbcglobal.net; R-help using r-project.org
Subject: Re: [R] Converting a list to a data frame

Others have shown you how to extract the matrix and convert it to a dataframe.  My only addition is to suggest that you don't do this: 
matrix methods are often much more efficient than dataframe methods, so if you can work with the matrix without conversion, you'll often find things run a lot faster.

Duncan Murdoch

On 24/07/2021 9:18 a.m., Jeff Reichman wrote:
> 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 using 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.
> 



More information about the R-help mailing list