Hi! I have thought of a pretty ugly way to solve this problem but am wondering if there are any solutions that are more elegant.
I have scores that correspond to a certain rank in df2 and want to create a new column in df1 called "rank" based off the information in df2. I thought about using "recode" for this and manually typing 171 = 1, 172 = 2, 173 = 3, and so on and so forth (and will do this if it's the only way) but there has to be a better way. I tired to short cut this by taking the columns in df2 as vectors and setting them equal in the recode function but it didn't work and I'm honestly not surprised. Here is the example:
# Example
score <- c(171, 175, 176, 188, 196)
participant <- c(1021, 1023, 1027, 1024, 1005)
df1 <- tibble(participant, score)
Rscore <- c(171, 172, 173, 174, 175, 176, 177, 178, 179,180, 181, 182, 183, 184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 195, 196)
Rrank <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 ,14 ,15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25)
df2 <- tibble(Rscore, Rrank)
df1 <- df1 %>% mutate(rank = recode(rank, Rscore = Rrank ))
## ^ this, not unsurprisingly, did not work
In the real data set I have thousands of scores that need to be aligned with a rank. Any thoughts would be warmly welcomed!
Sincerely,
M