In R, I am trying to take interview scores currently in a data frame like this:
Interviewer Applicant Score
Int_9 App_5 3
Int_3 App_3 2
Int_1 App_2 9
Int_3 App_5 2
...
and reformat to this:
AVG Int_1 Int_2 Int_3 ...
App_3 2.0 NA NA 2
App_5 2.5 NA NA 2
App_2 9.0 9 NA NA
...
This gets me close:
reshape(data, idvar="applicant", timevar="interviewer", direction="wide")
However, the interviewer names are not sorted alphabetically as I'd like. I suppose I could use the mean
and merge
functions to get the AVG column, but I don't know how to sort AVG from low to high (and have the rest of the entries come along for the ride). Also, how can I average over all the applicant scores without having to explicitly write the name of each applicant, i.e., how to not have to do this:
app_avg = c(mean(data$score[data$applicant=="App_1"]), mean(data$score[data$applicant=="App_2"]), mean(data$score[data$applicant=="App_3"]), ...)
Help, please?