-2

Any way to combine splits?

I have two splits, dfa and dfb.

dfa is a Large list (4 elements) with 4 variables i.e. dfa[[1]] selects the first split

dfb is also a Large list (11 elements) with the same 4 variables.

Is there any way to make it as follows:

dfc Large List (15 elements)

I want dfc[[1]] to be the same as dfa[[1]] and dfc[[5]] to be the same as dfb[[1]].

I have tried to bind these but cbind/rbind does not work.

hpesoj626
  • 3,529
  • 1
  • 17
  • 25
Aaron Walton
  • 21
  • 1
  • 5

2 Answers2

-1

If I understand your question correctly, you can try two things. If this doesn't solve your problem, do comment.

Sample Data:

dfa <- list(a = data.frame(a1 = c(1,2,3), b1 = c(2,3,4)),
            b = data.frame(a1 = c(4,5,6), b1 = c(5,6,7)))

Method1:

> library(dplyr)
> bind_rows(dfa)

  a1 b1
1  1  2
2  2  3
3  3  4
4  4  5
5  5  6
6  6  7

Method 2:

> library(purrr)
> map_df(dfa, rbind)

  a1 b1
1  1  2
2  2  3
3  3  4
4  4  5
5  5  6
6  6  7
YOLO
  • 20,181
  • 5
  • 20
  • 40
-1
dfa <- list(a = c("a", "b"), b = c(1:3), c = c(1:5), d = c("hello"))
dfb <- list(a = c(1:5), b = c(3:6), c = c("hello", "world"), d = c(5:6), e = c(5:6), f = c("hi", "hi"), g = c("hello", "there"), h = c(1:5))
dfc <- c(dfa, dfb)

dfc[[1]] gives you dfa[[1]] and dfc[[5]] gives you dfb[[1]]

DTYK
  • 1,098
  • 1
  • 8
  • 33