I would like to compute the row mean scores of columns A1 to E1.
library(dplyr)
df <- data.frame(A1 = c(1, 2, NA, 4),
                     B1 = c(2, 4, NA, 9),
                     C1 = c(6, 12, NA, 6),
                     D1 = c(22, 7, NA, 1),
                     E1 = c(11, 40, NA, 7),
                     F1 = c(22, 7, NA, 1),
                     G1 = c(2, 4, NA, 9),
                     H1 = c(11, 40, NA, 10)
               )
> df
  A1 B1 C1 D1 E1 F1 G1 H1
1  1  2  6 22 11 22  2 11
2  2  4 12  7 40  7  4 40
3 NA NA NA NA NA NA NA NA
4  4  9  6  1  7  1  9 10
This is my code so far:
df <- df %>%
  mutate(meanscores = rowMeans(subset(select = A1:E1)), na.rm = TRUE)
Thanks in advance!
 
     
    