Skip to content
Prev 350896 / 398502 Next

binding two lists of lists of dataframes together

On May 13, 2015, at 2:01 PM, Vin Cheng wrote:

            
I believe you are misrepresenting my suggestion. I suggested that you coerce each of the items in those lists to data.frames with appropriate column names before applying rbind.data.frame

Those list1 and list2 examples appear to me as pathologically deformed. They claim to be data.tables but they have no self referential pointers, suggesting to me that they are not data.tables, and they have no column names suggesting not either data.table, nor data.frame.
[1] "data.table" "data.frame"
[1] "data.table" "data.frame"
Fix up the data.structures, first. Then use Map(rbind, ...)   .... as described previously.

 list1a <- lapply(list1, function(x) setNames( data.frame(x), paste0("V", seq(length(x)) ) ) )
 list2a <- lapply(list2, function(x) setNames( data.frame(x), paste0("V", seq(length(x)) ) ))
 list3a <- Map( rbind.data.frame, list1a, list2a)
 str(list3a)

List of 3
 $ V1:'data.frame':	22 obs. of  8 variables:
  ..$ V1: int [1:22] 15 19 28 9 17 3 11 21 7 8 ...
  ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ...
  ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ...
  ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ V5: Factor w/ 29 levels "ID1","ID10","ID11",..: 7 11 21 29 9 23 3 14 27 28 ...
  ..$ V6: Factor w/ 29 levels "Issuer1","Issuer10",..: 7 11 21 29 9 23 3 14 27 28 ...
  ..$ V7: num [1:22] 99.5 95.5 99.5 100 98.5 ...
  ..$ V8: num [1:22] 0.4 0.55 0.4 0.4 0.5 0.45 0.4 0.45 0.6 0.4 ...
 $ V2:'data.frame':	22 obs. of  8 variables:
  ..$ V1: int [1:22] 10 29 5 19 28 3 10 12 1 21 ...
  ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ...
  ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ...
  ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ V5: Factor w/ 29 levels "ID1","ID10","ID11",..: 2 22 25 11 21 23 2 4 1 14 ...
  ..$ V6: Factor w/ 29 levels "Issuer1","Issuer10",..: 2 22 25 11 21 23 2 4 1 14 ...
  ..$ V7: num [1:22] 98.5 100.2 99 95.5 99.5 ...
  ..$ V8: num [1:22] 0.6 0.4 0.45 0.55 0.4 0.45 0.6 0.55 0.5 0.45 ...
 $ V3:'data.frame':	22 obs. of  8 variables:
  ..$ V1: int [1:22] 21 28 3 7 25 25 15 13 3 20 ...
  ..$ V2: num [1:22] 1 1 2 3 4 5 6 7 8 9 ...
  ..$ V3: num [1:22] NaN NaN NA NA NA NA NA NA NA NA ...
  ..$ V4: num [1:22] 0 0 0 0 0 0 0 0 0 0 ...
  ..$ V5: Factor w/ 29 levels "ID1","ID10","ID11",..: 14 21 23 27 18 18 7 5 23 13 ...
  ..$ V6: Factor w/ 29 levels "Issuer1","Issuer10",..: 14 21 23 27 18 18 7 5 23 13 ...
  ..$ V7: num [1:22] 98 99.5 99.6 99.8 99.4 ...
  ..$ V8: num [1:22] 0.45 0.4 0.45 0.6 0.4 0.4 0.4 0.4 0.45 0.3 ..