I have the following two test dfs:
df1 <- data.frame(block = c('1' , '1' , '1' , '2' , '2', '2' , '3' , '3' , '3') ,
type = c('a' , 'b' , 'c' , 'b' , 'a' , 'c' , 'c' , 'b' , 'a') ,
number = c('1' , '3' , '6' , '2' , '3' , '4' , '5' , '1' , '3'))
df2 <- data.frame(block = c('1' , '1' , '1' , '2' , '2', '2' , '3' , '3' , '3') ,
type = c('b' , 'c' , 'a' , 'c' , 'a' , 'b' , 'a' , 'c' , 'b') ,
value = c('3' , '2' , '3' , '5' , '1' , '6' , '3' , '2' , '1'))
I'd like to reorder the "value" column from df2 by the "type" column from df1. Then I'd like to merge the two dfs using cbind or similar and remove the extra "block" column in the output.
The output would look like:
df3 <- data.frame(block = c('1' , '1' , '1' , '2' , '2', '2' , '3' , '3' , '3') ,
type = c('a' , 'b' , 'c' , 'b' , 'a' , 'c' , 'c' , 'b' , 'a') ,
number = c('1' , '3' , '6' , '2' , '3' , '4' , '5' , '1' , '3') ,
value = c('3' , '3' , '2' , '6' , '1' , '5' , '2' , '1' , '3'))
A tidy verse method is preferred.