Convert a list of $NULL into multiple dataframes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Convert a list of $NULL into multiple dataframes

Ilio Fornasero
I have the following list:



> tables



    $`NULL`
                              V1     V2      V3
        1                   Year  1992  1993


     $`NULL`
                                 V1                           V2     V3    V4
          1                  Age Average (cm)     N       SD
          2                 18-19                        178.3  6309 6.39

I want to turn it into 2 dataframes:

A
$V1
$V2
$V3


B
$V1
$V2
$V3


Any easy hint?
Thanks




        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Convert a list of $NULL into multiple dataframes

R help mailing list-2
 There must be a simpler and easier way but it's early here and I am only on my first cup of tea.
Just but each element into a data frame.
Quick and dirty example:
============================dat1  <- list(aa = 1:20, bb  <- data.frame(xx = 1:5, yy = LETTERS[1:5]))

dat2 = data.frame(dat1[[1]])

======================================================

    On Friday, May 18, 2018, 4:37:39 a.m. EDT, Ilio Fornasero <[hidden email]> wrote:  
 
 I have the following list:



> tables



    $`NULL`
                              V1    V2      V3
        1                  Year  1992  1993


    $`NULL`
                                V1                          V2    V3    V4
          1                  Age Average (cm)    N      SD
          2                18-19                        178.3  6309 6.39

I want to turn it into 2 dataframes:

A
$V1
$V2
$V3


B
$V1
$V2
$V3


Any easy hint?
Thanks




    [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
 
        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Convert a list of $NULL into multiple dataframes

Jim Lemon-4
In reply to this post by Ilio Fornasero
Hi Ilio,
As far as I can see, this is what you have done:

A<-data.frame(V1="Year",V2=1992,V3=1993)
B<-data.frame(V1=c("Year","18-19"),V2=c("Average (cm)",178.3),
 V3=c("N",6309),V4=c("SD",6.39))
A
    V1   V2   V3
1 Year 1992 1993
B
     V1           V2   V3   V4
1  Year Average (cm)    N   SD
2 18-19        178.3 6309 6.39
# create "tables" from A and B
tables<-list("NULL"=A,"NULL"=B)
tables
$`NULL`
    V1   V2   V3
1 Year 1992 1993

$`NULL`
     V1           V2   V3   V4
1  Year Average (cm)    N   SD
2 18-19        178.3 6309 6.39
# recreate A by extracting the first element of "tables"
A<-tables[[1]]
A
    V1   V2   V3
1 Year 1992 1993
# recreate B by extracting the second element of "tables" minus the
fourth column
B<-tables[[2]][,-4]
B
B
    V1           V2   V3
1  Year Average (cm)    N
2 18-19        178.3 6309

Jim

On Fri, May 18, 2018 at 6:37 PM, Ilio Fornasero
<[hidden email]> wrote:

> I have the following list:
>
>
>
>> tables
>
>
>
>     $`NULL`
>                               V1     V2      V3
>         1                   Year  1992  1993
>
>
>      $`NULL`
>                                  V1                           V2     V3    V4
>           1                  Age Average (cm)     N       SD
>           2                 18-19                        178.3  6309 6.39
>
> I want to turn it into 2 dataframes:
>
> A
> $V1
> $V2
> $V3
>
>
> B
> $V1
> $V2
> $V3
>
>
> Any easy hint?
> Thanks
>
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.