head(somedata) ppt_id Q1 Q2 Q3 Q4 Q5 Q6
1 p1 4 3 2 5 4 2
2 p2 6 4 4 5 5 4
3 p3 3 1 4 5 6 5
4 p4 3 1 5 6 3 6
5 p5 6 6 5 4 3 3
6 p6 3 3 3 4 5 7
Typically scale scores are either mean scores or sum scores. These are, for each person, the mean, or the sum, of their scores on each item.
Because we are wanting this for each person, and each person is a row in our dataset, so we want row means, or row sums.
If our data looks like the below, where we have six questions for which we wish to create a score:
head(somedata) ppt_id Q1 Q2 Q3 Q4 Q5 Q6
1 p1 4 3 2 5 4 2
2 p2 6 4 4 5 5 4
3 p3 3 1 4 5 6 5
4 p4 3 1 5 6 3 6
5 p5 6 6 5 4 3 3
6 p6 3 3 3 4 5 7
To calculate mean/sum scores, we can just use rowMeans or rowSums.
We can do this by using the positions of the relevant columns:
somedata$meanscore <- rowMeans(somedata[,2:7])
somedata$sumscore <- rowSums(somedata[,2:7])Or in tidyverse syntax:
somedata <-
somedata |> mutate(
meanscore = rowMeans(pick(Q1:Q6)),
sumscore = rowSums(pick(Q1:Q6)),
)