I have 2 dataframes:
df1=data.frame(col1=c('A', 'A', 'B', 'B', 'B'),
col2a=c(1, 4, 3, 2, 5))
df2=data.frame(col1=c('A', 'A', 'A', 'B', 'B'),
col2b=c('a', 'd', 'c', 'b', 'e'))
I want to have a resulted df like this:
df3=data.frame(col1=c('A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B'),
col2b=c('a', 'a', 'd', 'd', 'c', 'c', 'b', 'b', 'b', 'e', 'e', 'e'),
col2a=c(1, 4, 1, 4, 1, 4, 3, 2, 5, 3, 2, 5))
I have tried to use merge() for df1 and df2 by column col1 but it doesn't work because col1 is a non-unique column. Can anyone help me with this?