Re: [R] Converting a list to a data frame

2021-07-24 Thread Duncan Murdoch
r large "list" over 1 million rows. It is possible to work with a matrix in ggplot2? Jeff -Original Message- From: Duncan Murdoch Sent: Saturday, July 24, 2021 12:03 PM To: reichm...@sbcglobal.net; R-help@r-project.org Subject: Re: [R] Converting a list to a data frame Oth

Re: [R] Converting a list to a data frame

2021-07-24 Thread Jeff Reichman
Thanks for the tips -Original Message- From: Rui Barradas Sent: Saturday, July 24, 2021 11:40 AM To: reichm...@sbcglobal.net; R-help@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

Re: [R] Converting a list to a data frame

2021-07-24 Thread Rui Barradas
over 1 million rows. It is possible to work with a matrix in ggplot2? Jeff -Original Message- From: Duncan Murdoch Sent: Saturday, July 24, 2021 12:03 PM To: reichm...@sbcglobal.net; R-help@r-project.org Subject: Re: [R] Converting a list to a data frame Others have shown you how to

Re: [R] Converting a list to a data frame

2021-07-24 Thread Jeff Reichman
uly 24, 2021 12:03 PM To: reichm...@sbcglobal.net; R-help@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

Re: [R] Converting a list to a data frame

2021-07-24 Thread Duncan Murdoch
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 f

Re: [R] Converting a list to a data frame

2021-07-24 Thread Rui Barradas
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

Re: [R] Converting a list to a data frame

2021-07-24 Thread Bert Gunter
Here is a reprex that does what I think you want: ex <- list(mcmc = matrix(1:12, ncol = 3, byrow=TRUE), NULL, c("a","b", "s")) dex <- data.frame(ex$mcmc) names(dex) <- ex[[3]] > dex a b s 1 1 2 3 2 4 5 6 3 7 8 9 4 10 11 12 If this is not correct, you should provide a **

[R] Converting a list to a data frame

2021-07-24 Thread Jeff Reichman
How does one convert a list into a data frame? > str(weight_chains) List of 1 $ : 'mcmc' num [1:10, 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"

Re: [R] Converting a list to a data frame

2018-05-04 Thread Bill Poling
Oh, how funny, hence the term Novice usR. UGH! Thank you Sir. WHP From: Kevin E. Thorpe [mailto:kevin.tho...@utoronto.ca] Sent: Friday, May 04, 2018 9:08 AM To: Bill Poling ; Huzefa Khalil Cc: R Help Mailing List Subject: Re: [R] Converting a list to a data frame It looks like you made a

Re: [R] Converting a list to a data frame

2018-05-04 Thread Bill Poling
"ata.frame"? William H. Poling, Ph.D. From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Huzefa Khalil Sent: Wednesday, May 02, 2018 1:24 PM To: Kevin E. Thorpe Cc: R Help Mailing List Subject: Re: [R] Converting a list to a data frame Hi Kevin, There is probably a better

Re: [R] Converting a list to a data frame

2018-05-04 Thread Kevin E. Thorpe
May 02, 2018 1:24 PM *To:* Kevin E. Thorpe *Cc:* R Help Mailing List *Subject:* Re: [R] Converting a list to a data frame Hi Kevin, There is probably a better way, but it can be done in two steps like this temp <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) temp <- lapply

Re: [R] Converting a list to a data frame

2018-05-03 Thread William Dunlap via R-help
If you require that the 'type' column be a factor with a level for each element of the input list, then you need to do that after calling dplyr::bind_rows(), just as with the base-R solutions. > l <- list( A = data.frame(X=1:2, Y=11:12), B = data.frame(X=integer(), Y=integer()), C = data.frame(X=3

Re: [R] Converting a list to a data frame

2018-05-03 Thread Kevin E. Thorpe
On 05/03/2018 01:28 PM, Hadley Wickham wrote: On Wed, May 2, 2018 at 11:53 AM, Jeff Newmiller wrote: Another approach: library(tidyr) L <- list( A = data.frame( x=1:2, y=3:4 ) , B = data.frame( x=5:6, y=7:8 ) ) D <- data.frame( Type = names( L ) , s

Re: [R] Converting a list to a data frame

2018-05-03 Thread Hadley Wickham
On Wed, May 2, 2018 at 11:53 AM, Jeff Newmiller wrote: > Another approach: > > > library(tidyr) > L <- list( A = data.frame( x=1:2, y=3:4 ) > , B = data.frame( x=5:6, y=7:8 ) > ) > D <- data.frame( Type = names( L ) >, stringsAsFactors = FALSE >

Re: [R] Converting a list to a data frame

2018-05-03 Thread David Winsemius
A NA ... -- David, the other. > > David C > > -Original Message- > From: R-help On Behalf Of David L Carlson > Sent: Wednesday, May 2, 2018 3:51 PM > To: William Dunlap ; Kevin E. Thorpe > > Cc: r-help mailing list > Subject: Re: [R] Converting a list to

Re: [R] Converting a list to a data frame

2018-05-03 Thread Kevin E. Thorpe
p and David Carlson is beautifully elegant. Thanks again, Kevin -Original Message- From: R-help On Behalf Of David L Carlson Sent: Wednesday, May 2, 2018 3:51 PM To: William Dunlap ; Kevin E. Thorpe Cc: r-help mailing list Subject: Re: [R] Converting a list to a data frame Or add th

Re: [R] Converting a list to a data frame

2018-05-03 Thread Martin Maechler
William Dunlap ; Kevin E. Thorpe > > Cc: r-help mailing list > Subject: Re: [R] Converting a list to a data frame > > Or add the type column first and then rbind: > > x <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) > x2 <- do.call(rbind, lapply(names(

Re: [R] Converting a list to a data frame

2018-05-03 Thread Tóth Dénes
On 05/03/2018 07:58 AM, Jeff Newmiller wrote: This is very nice to learn about, Denis, but it seems only fair to point out that the result of rbindlist is not a data frame. You can convert it to a data frame easily, but the copy and indexing semantics of data tables are quite different than

Re: [R] Converting a list to a data frame

2018-05-02 Thread Jeff Newmiller
This is very nice to learn about, Denis, but it seems only fair to point out that the result of rbindlist is not a data frame. You can convert it to a data frame easily, but the copy and indexing semantics of data tables are quite different than data tables, which could be a real headache for s

Re: [R] Converting a list to a data frame

2018-05-02 Thread David L Carlson
To: William Dunlap ; Kevin E. Thorpe Cc: r-help mailing list Subject: Re: [R] Converting a list to a data frame Or add the type column first and then rbind: x <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) x2 <- do.call(rbind, lapply(names(x), function(z) data.fra

Re: [R] Converting a list to a data frame

2018-05-02 Thread David L Carlson
as A&M University College Station, TX 77843-4352 -Original Message- From: R-help On Behalf Of William Dunlap via R-help Sent: Wednesday, May 2, 2018 12:28 PM To: Kevin E. Thorpe Cc: R Help Mailing List Subject: Re: [R] Converting a list to a data frame > x1 <- do.call(

Re: [R] Converting a list to a data frame

2018-05-02 Thread Tóth Dénes
On 05/02/2018 07:11 PM, Kevin E. Thorpe wrote: I suspect this is pretty easy, but I'm having trouble figuring it out. Basically, I have a list of data frames such as the following example: list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) I would like to turn this into data frame w

Re: [R] Converting a list to a data frame

2018-05-02 Thread Jeff Newmiller
Another approach: library(tidyr) L <- list( A = data.frame( x=1:2, y=3:4 ) , B = data.frame( x=5:6, y=7:8 ) ) D <- data.frame( Type = names( L ) , stringsAsFactors = FALSE ) D$data <- L unnest(D, data) #> Type x y #> 1A 1 3 #> 2A

Re: [R] Converting a list to a data frame

2018-05-02 Thread Eivind K. Dovik
On Wed, 2 May 2018, Kevin E. Thorpe wrote: I suspect this is pretty easy, but I'm having trouble figuring it out. Basically, I have a list of data frames such as the following example: list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) I would like to turn this into data frame where

Re: [R] Converting a list to a data frame

2018-05-02 Thread William Dunlap via R-help
> x1 <- do.call(rbind, c(x, list(make.row.names=FALSE))) > x2 <- cbind(type=rep(names(x), vapply(x, nrow, 0)), x1) > str(x2) 'data.frame': 4 obs. of 3 variables: $ type: Factor w/ 2 levels "A","B": 1 1 2 2 $ x : int 1 2 5 6 $ y : int 3 4 7 8 Bill Dunlap TIBCO Software wdunlap tibco.co

Re: [R] Converting a list to a data frame

2018-05-02 Thread Huzefa Khalil
Hi Kevin, There is probably a better way, but it can be done in two steps like this temp <- list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) temp <- lapply(names(temp), function(n, temp) { temp[[n]]$type <- n return(temp[[n]]) }, temp = temp) do.call(rbind, temp) On Wed, May 2,

[R] Converting a list to a data frame

2018-05-02 Thread Kevin E. Thorpe
I suspect this is pretty easy, but I'm having trouble figuring it out. Basically, I have a list of data frames such as the following example: list(A=data.frame(x=1:2, y=3:4),B=data.frame(x=5:6,y=7:8)) I would like to turn this into data frame where the list elements are essentially rbind'ed t

Re: [R] Converting a list to a data frame

2016-11-04 Thread Bert Gunter
I believe that a slightly more efficient way of doing this without leaving base R is: cbind(do.call(rbind,x), set = rep(seq_along(x), vapply(x,nrow,1)) ) Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka

Re: [R] Converting a list to a data frame

2016-11-04 Thread Carlos Ortega
Hi, You have also "rbindlist()" function in package "data.table" that does exactly what you need. Kind Regards, Carlos Ortega www.qualityexcellence.es 2016-11-04 13:37 GMT+01:00 Kevin E. Thorpe : > There is probably a very simple elegant way to do this, but I have been > unable to find it. He

Re: [R] Converting a list to a data frame

2016-11-04 Thread Charles Determan
Hi Kevin, There may be a more elegant way but the following do.call and lapply should solve your problem. do.call(rbind, lapply(seq(length(x)), function(i) data.frame(set=i, x[[i]]))) Regards, Charles On Fri, Nov 4, 2016 at 7:37 AM, Kevin E. Thorpe wrote: > There is probably a very simple ele

[R] Converting a list to a data frame

2016-11-04 Thread Kevin E. Thorpe
There is probably a very simple elegant way to do this, but I have been unable to find it. Here is a toy example. Suppose I have a list of data frames like this. print(x <- list('1'=data.frame(id=1:4,expand.grid(x1=0:1,x2=0:1)),'2'=data.frame(id=5:8,expand.grid(x1=2:3,x2=2:3 $`1` id x1

Re: [R] Converting a list to a data frame or columns at the least

2009-05-26 Thread Glen Sargeant
Farrel Buchinsky-3 wrote: > > I have a column in which dates and times are specified thus > m/d/ HH:MM:SS > Alas, some entries do not include the time and therefore are only > m/d/ > so I used read.csv and specified that the relevant column should be read > as > is and it remained as a

[R] Converting a list to a data frame or columns at the least

2009-05-26 Thread Farrel Buchinsky
I have a column in which dates and times are specified thus m/d/ HH:MM:SS Alas, some entries do not include the time and therefore are only m/d/ so I used read.csv and specified that the relevant column should be read as is and it remained as a character variable. I then split the value on