[R] Convert a list of $NULL into multiple dataframes

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Fri May 18 12:22:16 CEST 2018


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
<iliofornasero using hotmail.com> 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]]
>
> ______________________________________________
> 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