If I have a data frame like this, which can be think as the responses of a survey for different respondents
Data =
ID Q1 Q2 Q3
1 A1 B2 C3
2 A2 B1 C2
3 A1 B2 C3
...
and I also have the following score tables:
Q1 <- (c("A1", 10, "A2", 20, ...))
Q2 <- (c("B1", 10, "B2", 20, ...))
Q3 <- (c("C1", 10, "C2", 20, ...))
which mean that, if I choose “A1” in Q1, I get 10 marks, if I choose “B2” in Q2, I get 20 marks more, and if I choose “C1” in Q3, That is also 10 marks, the total score I got would be:
10 (A1) + 20 (B2) + 10 (C1) = 40
And now for every row in the Data, I need to calculation the total score by summing the scores for each columns according to the score tables.
Can any one suggest me how I can use a simple code to do so?
For now I can only think of make the score tables in to a Xx2 Matrices, and use a lot of nested-if and for-loop.
1 Answer