I have 3 lists, each with n elements of length fixed (10 in the example):
my_list <- list(1:10,11:20,21:30)
my_list2 <- list(31:40,41:50,51:60)
my_list3 <- list(rep("a", 10), rep("b", 10), rep("c", 10))
I'd like to put them in a list of data.frames, combining "vertically" each list element:
final <- list(
tb1 = data.frame(v1=1:10, v2=31:40, v3=rep("a",10)),
tb2 = data.frame(v1=11:20, v2=41:50, v3=rep("b", 10)),
tb3 = data.frame(v1=21:30, v2=51:60, v3=rep("c", 10))
)
# map(final, head, 2)
# $`tb1`
# v1 v2 v3
# 1 1 31 a
# 2 2 32 a
#
# $tb2
# v1 v2 v3
# 1 11 41 b
# 2 12 42 b
#
# $tb3
# v1 v2 v3
# 1 21 51 c
# 2 22 52 c
With c and rbind at least I combined them in the right order, but I can't think of a way to put them in a data.frame "every 3 elements".
ab <- c(rbind(my_list, my_list2, my_list3))
# head(ab,3)
# [[1]]
# [1] 1 2 3 4 5 6 7 8 9 10
#
# [[2]]
# [1] 31 32 33 34 35 36 37 38 39 40
#
# [[3]]
# [1] "a" "a" "a" "a" "a" "a" "a" "a" "a" "a"