[R] binding two lists of lists of dataframes together
David Winsemius
dwinsemius at comcast.net
Tue May 12 20:36:50 CEST 2015
On May 12, 2015, at 9:24 AM, Vin Cheng wrote:
> list1<-list(structure(list(id = c(493L, 564L, 147L, 83L, 33L, 276L, 402L, 285L, 30L, 555L),
> WgtBand = c(1, 1, 2, 3, 4, 5, 6, 7, 8, 9),
> Wgt = c(NaN, NaN, NA, NA, NA, NA, NA, NA, NA, NA)),
> .Names = c("id", "WgtBand", "Wgt")),
> structure(list(id = c(76L, 330L, 574L, 47L, 131L, 581L, 133L, 69L, 35L, 487L),
> WgtBand = c(1, 1, 2, 3, 4,5, 6, 7, 8, 9),
> Wgt = c(NaN, NaN, NA, NA, NA, NA, NA, NA, NA, NA)),
> .Names = c("id", "WgtBand", "Wgt")),
> structure(list(id = c(376L, 130L, 574L, 47L, 131L, 581L, 133L, 69L, 35L, 487L),
> WgtBand = c(1, 1, 2, 3, 4,5, 6, 7, 8, 9),
> Wgt = c(NaN, NaN, NA, NA, NA, NA, NA, NA, NA, NA)),
> .Names = c("id", "WgtBand", "Wgt")))
>
>
> list2<-list(structure(list(id = c(493L, 564L, 147L),
> WgtBand = c(1, 2, 3),
> Wgt = c(NaN, NaN, NA)),
> .Names = c("id", "WgtBand", "Wgt")),
> structure(list(id = c(276L, 411L, 574L,111L),
> WgtBand = c(1, 2, 3,4),
> Wgt = c(NaN, NaN, NA,NA)),
> .Names = c("id", "WgtBand", "Wgt")),
> structure(list(id = c(76L, 330L),
> WgtBand = c(1, 1),
> Wgt = c(NaN, NaN)),
> .Names = c("id", "WgtBand", "Wgt")))
>
> list3<-list(structure(list(id = c(493L, 564L, 147L, 83L, 33L, 276L, 402L, 285L, 30L, 555L,493L, 564L, 147L),
> WgtBand = c(1, 1, 2, 3, 4, 5, 6, 7, 8, 9,1, 2, 3),
> Wgt = c(NaN, NaN, NA, NA, NA, NA, NA, NA, NA, NA,NaN, NaN, NA)),
> .Names = c("id", "WgtBand", "Wgt")),
> structure(list(id = c(376L, 130L, 574L, 47L, 131L, 581L, 133L, 69L, 35L, 487L,276L, 411L, 574L,111L),
> WgtBand = c(1, 1, 2, 3, 4,5, 6, 7, 8, 9, 1, 2, 3,4),
> Wgt = c(NaN, NaN, NA, NA, NA, NA, NA, NA, NA, NA,NaN, NaN, NA,NA)),
> .Names = c("id", "WgtBand", "Wgt")),
> structure(list(id = c(76L, 330L, 574L, 47L, 131L, 581L, 133L, 69L, 35L, 487L,76L, 330L),
> WgtBand = c(1, 1, 2, 3, 4,5, 6, 7, 8, 9, 1, 1),
> Wgt = c(NaN, NaN, NA, NA, NA, NA, NA, NA, NA, NA,NaN, NaN)),
> .Names = c("id", "WgtBand", "Wgt")))
I get something like the desired structure with:
mapply(function(x,y) mapply(c, x,y), list1,list2)
I can make it closer with:
lapply( mapply(function(x,y) mapply(c, x,y), list1,list2) , function(x) unclass( as.data.frame(x) ) )
Or even closer with:
lapply( mapply(function(x,y) mapply(c, x,y), list1,list2) , function(x) as.list( as.data.frame(x) ) )
`identical` does not return TRUE but I cannot see where the difference lies.
--
David Winsemius
Alameda, CA, USA
More information about the R-help
mailing list