I am trying to display multiple dataframes next to each other to compare certain entries. However, they have a different number of rows and I want each data frame to be in the exact same order.
I tried to use cbind
which did not work because of the different number of rows. I used merge
to bind two dfs together and then merge them again, however they change order when I do that and it seems inefficient to merge two dfs when I have more than 5 in total.
Examp:
df <- data.frame(v=1:5, x=sample(LETTERS[1:5],5))
df
v x
1 1 E
2 2 B
3 3 D
4 4 C
5 5 A
df2 <- data.frame(m=7:10, n=sample(LETTERS[6:9],4))
df2
m n
1 7 G
2 8 I
3 9 F
4 10 H
Then I ordered df2
df2 <- df2[order(df2$m, decreasing = TRUE),]
df2
m n
4 10 F
3 9 I
2 8 H
1 7 G
Expected output:
v x m n
1 1 E 10 F
2 2 B 9 I
3 3 D 8 H
4 4 C 7 G
5 5 A NA NA
As I said, I have more than two dfs and the order of the dfs should be remained. Any help will be greatly appreciated!