First, I apologize for the somewhat non-descriptive title but as you can probably see below, the problem is not easy to sum up in a single question.
I have a data set of peer evaluations, where group members rated each other on a set of criteria. Unfortunately, I wasn't able to pre-populate respondents' group members in the the survey so I ended up with a very jumbled data set that looks like this:
data = data.frame(gm1 = c("Lin", "Bill", "Cass", "Dan"),
gm2 = c("Bill", "Lin", "Bill", "Lin"),
gm3 = c("Cass", "Dan", "Lin", "Cass"),
gm4 = c("Dan", "Cass", "Dan", "Bill"),
crit1_1 = c(5, 2, 4, 4),
crit1_2 = c(5, 3, 3, 3),
crit1_3 = c(4, 2, 4, 4),
crit1_4 = c(5, 5, 4, 4))
where gm1 is the respondent and crit1 represents their self-ratings and gm2-4 are their group members with crit1_2-4 representing their ratings of each member on the first criteria (there are multiple). I need to calculate the average of the group's ratings for each member but as you can see, there is no consistent pattern for who is gm1-4. For example, for Lin, I need an average of Bill, Cass, and Dan's ratings of Lin.
I know this is a bit of a mess but I hoping there is a relatively simple way of transforming this data so that I can perform the calculations that I need to.
I've thought about assigning each group member a number like so
key = data.frame(gm1 = c("Lin", "Bill", "Cass", "Dan"),
num = c(1, 2, 3, 4))
data1 = data[ , c(1,2,3,4)]
data1[] <- key$num[match(unlist(data), key$gm1)]
data2 = cbind(data1, data[ , -c(1,2,3,4)])
and then sorting columns gm1-4 so that the pattern is always the same for each criteria. However, I do not know how to sort gm1-4 for each row in such a way that creates corresponding changes in crit1_1-4.
Any suggestions would be much appreciated!
crit1_2-4.