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]]
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 <iliofornasero
at 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 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.
[[alternative HTML version deleted]]
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 at 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 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.