I want to merge two data frames with approximately same number of rows. But the merging needs to be done in a special way.
Suppose the two data frames are A
and B
. and Ai
, Bi
represent the i
th row of the respective data frames.
Then I want a new dataframe with the following rows:
A1
B1
A2
B2
...
Here is a toy example:
A <- data.frame(col1 = paste("A", 1:5, sep = ""), col2 = rivers[1:5])
B <- data.frame(col1 = paste("B", 1:6, sep = ""), col2 = rivers[1:6])
I want a new data frame C such that
> C
col1 col2
1 A1 735
6 B1 735
2 A2 320
7 B2 320
...
How do I efficiently do it in R? Please note, there are no empty rows between two rows, as it appears here.
merge
function. Pay special attention to Example section of the helpfile.merge
. Are there the same columns inA
andB
?