I have two data frames df1 and df2 containing three columns L, M, and G.
df1 <- data.frame(L= c(0, 1,1,2,2,2,3,3,3,3), M= c(0,0,1,0,1,2,0,1,2,3), G= (1:10))
df2<- data.frame(L=c(0,1,2,3,1,2,3,2,3,3), M= c(0,0,0,0,1,1,1,2,2,3), G= c(12, 13, 4, 6, 7, 54, 87,56,3,0))
Keeping the df1 as it is with no changes. But, I want to reshuffle the L and M of df2 to be the same sort as df1, while keeping the corresponding values of G in df2 intact I want to get the following results
desired_result <- data.frame(L= c(0,1,1,2,2,2,3,3,3,3), M= c(0,0,1,0,1,2,0,1,2,3), G= c(12,13,7,4,54,56,6,87,3,0))
You can do a simple join after removing the
Gcolumn fromdf1.Equivalent in base R :