This function takes a list of lists of data.tables (or anything that data.table::rbind accepts, like data.frames), and then row-binds them by position or name. For example, if passed list(list(first=A,second=B),list(first=C,second=D)), you would get back list(first=rbind(A,C),second=rbind(B,D)).

rbind_by_list_pos(dtl, ignore_names = FALSE)

Arguments

dtl

List of lists of data.tables.

ignore_names

If the list is named, match objects across lists only by their position in the list and not by their names.

Examples


list_of_lists <- list(
    list(data.frame(a = 1), data.frame(a = 2), data.frame(a = 3)),
    list(data.frame(a = 4), data.frame(a = 5), data.frame(a = 6))
)
rbind_by_list_pos(list_of_lists)
#> [[1]]
#>    a
#> 1: 1
#> 2: 4
#> 
#> [[2]]
#>    a
#> 1: 2
#> 2: 5
#> 
#> [[3]]
#>    a
#> 1: 3
#> 2: 6
#> 

list_of_named_lists <- list(
    list(A = data.frame(a = 1), B = data.frame(a = 2), C = data.frame(a = 3)),
    list(C = data.frame(a = 4), A = data.frame(a = 5), B = data.frame(a = 6))
 )
rbind_by_list_pos(list_of_named_lis)
#> Error in rbind_by_list_pos(list_of_named_lis): object 'list_of_named_lis' not found