Quantcast
Channel: Merging lists of data frames with different length - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Merging lists of data frames with different length

$
0
0

I want to merge two lists of data frames. The lists have different length and the data frames in them also.

ls(df_list1) [1] "0""1""14""15""16""19""2""23""25""29""3""31""32""33""36""38""4""46""48""5""57""6""61""63"[25] "7""8""9"ls(df_list2) [1] "0""1""10""15""16""17""19""2""24""26""3""30""32""33""34""37""39""4""47""49""5""58""6""62"[25] "64""7""8""9"

I want to merge every dataframe from df_list1 with every dataframe from df_list2.

Tried this, but I can`t save all the combinations to test, just the last merge from the cycle.

test=list()for (i in 1:length(df_list1){  for (j in 1:length(df_list2){      test[[i]] <- inner_join(df_list1[[i]], df_list2[[j]], by="variable")  }}

Maybe something like this:

df_list1 <- list("0"=data.frame("variable" = c(2,4,8), "variable2" = c(13,14,53), "variable1" = "2019-05-31"),"1"=data.frame("variable" = c(3,7,2), "variable2" = c(53,68,41), "variable1" = "2019-05-31"),"4"=data.frame("variable" = c(6,5,6), "variable2" = c(24,52,83), "variable1" = "2019-05-31"))df_list2 <- list("0"=data.frame("variable" = c(2,8,3), "variable2" = c(72,25,37), "variable1" = "2019-05-31"),"3"=data.frame("variable" = c(2,7,6), "variable2" = c(24,62,45), "variable1" = "2019-05-31"),"4"=data.frame("variable" = c(9,5,8), "variable2" = c(34,74,58), "variable1" = "2019-05-31"))

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images