1

I have a raw test score on n subjects, and a previously validated conversion table that links each possible raw score to a t-score and an SE. The goal is to assign the correct tscore and SE to each subject.

The following produces the desired outcome but the conversion table has many rows so this gets ugly. Any suggestions for a more elegant solution welcome!

raw<-data.frame(obsval=c(8,8,2,5,5))
tse<-data.frame(score=c(2,5,8),ts=c(1,2,3),se=c(0.1,0.2,0.3))

raw <- raw %>%
  mutate(tscore = case_when( 
  raw == tse[1,1] ~ tse[1,2],
  raw == tse[2,1] ~ tse[2,2],
  raw == tse[3,1] ~ tse[3,2],
  )) %>% 
mutate (SE = case_when(
  raw == tse[1,1] ~ tse[1,3],
  raw == tse[2,1] ~ tse[2,3],
  raw == tse[3,1] ~ tse[3,3],
))
M--
  • 25,431
  • 8
  • 61
  • 93
Gitta
  • 15
  • 2
  • 3
    Take a look at [`left_join`](https://dplyr.tidyverse.org/reference/mutate-joins.html). i.e. `left_join(raw, tse, by = c("obsval" = "score"))` – benson23 Mar 16 '23 at 02:48

0 Answers0