I have a large spreadsheet of team member ratings from which I want to calculate how people rated themselves, how they were rated by everyone else on their team, and how they rated everyone else on their team (all averages). I've been trying to do this with dplyr
because I have used it before and I think that the group_by
will simplify things when doing these calculations. I haven't been able to figure it out so I'm asking for help. I'll try to explain my thinking.
Here's an example dataset:
data <- read.table(text="
Team Rater A1 B1 C1 A2 B2 C2 A3 B3 C3 A4 B4 C4 A5 B5 C5 A6 B6 C6
1 1 2 4 4 2 1 5 2 2 3 4 4 4 3 2 1 NA NA NA
1 2 4 5 4 4 5 1 1 1 5 5 3 1 4 5 2 NA NA NA
1 3 2 1 4 3 5 5 2 1 5 1 1 4 1 1 4 NA NA NA
1 4 4 3 4 3 5 1 3 1 3 5 5 5 5 2 2 NA NA NA
1 5 3 4 5 4 3 3 5 5 4 1 4 5 5 5 1 NA NA NA
2 1 3 5 3 4 1 1 3 4 3 4 3 2 2 2 3 3 5 3
2 2 3 2 3 1 1 3 5 5 1 5 2 3 2 2 1 3 3 2
2 3 3 2 3 3 5 2 4 1 1 1 4 5 3 5 2 1 1 3
2 4 3 3 5 4 3 5 3 1 4 3 1 1 4 2 4 3 5 2
2 5 5 2 1 2 5 5 3 3 1 4 1 5 5 3 3 4 2 5
2 6 3 2 3 5 4 3 2 1 5 4 3 1 1 1 4 2 2 1",header = TRUE)
Each rater provides input on multiple questions for each other team member. The way it is organized, rater 1 answers A1, B1, and C1 about themselves. Rater 2 answers A2, B2, and C2 about themselves, and so on.
Self Ratings
To get someone's rating of themselves I figured it would be something like:
data %>%
group_by(Team) %>%
mutate(self = rowMeans(select(.,ends_with(Rater)), na.rm = TRUE))
It'd be convenient if the column selection was dynamically based on their rater number.
From Others
I was thinking of calculating this based on the average overall rating of that person except the self rating:
data %>%
group_by(Team) %>%
mutate(from = ( (mean(ends_with(Rater)) * n() - self ) / ( n() - 1 ) ) )
Of Others
For this column calculation I was thinking something along the lines of:
data %>%
mutate(of = select(A1:C6, -(ends_with(Rater))) %>% rowMeans(na.rm = TRUE))
(similar to this answer)
Results
Here is an example of what I'm looking for as new columns:
Team Rater self from of
1 1 3.33 3.58 2.75
1 2 3.33 3.33 3.33
1 3 2.67 2.92 2.67
1 4 5.00 3.08 3.00
1 5 3.67 2.67 3.83
If you can help with any of these parts I'd appreciate it!