I have three data-frames, each of a single column, but of different lengths, each with a distinct header. How do I join them into a single data-frame? Example of input.
df1> Case 1 df2> Case 2 df3> Case 3
ABCCD TCGGS ZCRTTS
PCCGT GCQZZ
XGGTS
I'd like to combine them into a single table or data-frame, like:
Case 1 Case 2 Case 3
ABCCD TCGGS ZCRTTS
PCCGT GCQZZ
XGGTS
I've tried using merge and join, but I don't get the result above.
Interesting. So the first step is to remove the headers, then combine the df and finally add the column names. I'll give it a shot and let you know. Thanks.
Anyhow, have you considered merge's all.x/all.y arguments? dplyr's left_join/right_join offer the same functionality and are explained in detail here: https://r4ds.had.co.nz/relational-data.html.
A data frame is a list of variables of the same number of rows with unique row names, given class "data.frame" . If no variables are included, the row names determine the number of rows.
Further down
Objects passed to data.frame should have the same number of rows, but atomic vectors (see is.vector ), factors and character vectors protected by I will be recycled a whole number of times if necessary (including as elements of list arguments).
You could replace NA with some other desired value (e.g. an empty string), but something has to be there to maintain the structure of the object.
the package sjmisc, has a convenient helper for this. sjmisc::replace_na()
testframe <- tribble(~a, ~b,
"X",NA,
NA,NA)
> testframe
# A tibble: 2 x 2
a b
<chr> <lgl>
1 X NA
2 NA NA
replace_na(testframe,value="")
# A tibble: 2 x 2
a b
<chr> <chr>
1 "X" ""
2 "" ""