This question probably has been answered before, but I can't seem to find the answer. How do you use bind_rows()
to just union
the two tables and ignore the column names.
The documentation on bind_rows()
has the following example:
#Columns don't need to match when row-binding
bind_rows(data.frame(x = 1:3), data.frame(y = 1:4))
This returns column x
and y
. How do I just get a single column back without having to change the column names?
Desired output, I don't really care what the column name ends up being:
x
1 1
2 2
3 3
4 1
5 2
6 3
7 4
You can do this with a quick 2-line function:
force_bind = function(df1, df2) {
colnames(df2) = colnames(df1)
bind_rows(df1, df2)
}
force_bind(df1, df2)
Output:
x
1 1
2 2
3 3
4 1
5 2
6 3
7 4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With