I need to create a dataframe whose variables are recoded values of another dataframe.
The data matrix has a column of people who are rated by a group of raters plus an expert rater. Here's what the data structure looks like (these are just made-up values):
person <- c(1:10)
rater.1 <- c(2,3,2,3,4,3,4,2,3,3)
rater.2 <- c(4,3,2,3,1,2,3,2,3,1)
rater.3 <- c(3,2,3,1,2,2,2,3,1,2)
rater.4 <- c(3,4,3,4,3,4,2,2,3,2)
expert.rater <- c(4,4,2,3,1,2,1,2,2,2)
ratings <- data.frame(person,rater.1,rater.2, rater.3, rater.4, expert.rater)
Except in my real data set I have 131 raters and 400 people.
I need to compare each rater to the expert and make a new dataframe of the difference scores. I can think of doing it this way, except it is very tedious and probably not a good idea:
rater.1_a <- abs(rater.1 - expert.rater)
rater.2_a <- abs(rater.2 - expert.rater)
rater.3_a <- abs(rater.3 - expert.rater)
rater.4_a <- abs(rater.4 - expert.rater)
difference <- data.frame(person,rater.1_a,rater.2_a, rater.3_a, rater.4_a)
Is there a quicker way to create the 131 new rater.x_a variables?