I would like to merge two dataframe into one, each cell becoming a vector or a list. Columns have the same name in both dataframes. Some columns are made of numerical values that I want to keep as numerical values in the merged dataframe. Some columns are made of characters.
For example I would like from these two dataframes:
DF1 <- data.frame(
xx = c(1:5),
yy = c(2:6),
zz = c("a","b","c","d","e"))
DF2 <- data.frame(
xx = c(3:7),
yy = c(5:9),
zz = c("a","i","h","g","f"))
Which look like this:
DF1
| xx | yy | zz |
|---|---|---|
| 1 | 2 | a |
| 2 | 3 | b |
| 3 | 4 | c |
| 4 | 5 | d |
| 5 | 6 | e |
DF2
| xx | yy | zz |
|---|---|---|
| 3 | 5 | a |
| 4 | 6 | i |
| 5 | 7 | h |
| 6 | 8 | g |
| 7 | 9 | f |
To get a dataframe looking like this:
| xx | yy | zz |
|---|---|---|
| c(1,3) | c(2,5) | c(a,a) |
| c(2,4) | c(3,6) | c(b,i) |
| c(3,5) | c(4,7) | c(c,h) |
| c(4,6) | c(5,8) | c(d,g) |
| c(5,7) | c(6,9) | c(e,f) |
I have tried with paste() or str_c() but it always transforms my numerical values into char and it does not create a list or a vector like I want.
Do you know of any functions that coule help me do that?