To make an accuracy score, we’ll get a proportion of correct answers for each subject in our new MemoryTest data frame:
MemoryTest$MemoryScore <- rowSums(MemoryTest) / ncol(MemoryTest)
Code translation: We make a new column in the MemoryTest dataframe called MemoryScore. In this new column, each row will take the sum of all the other cells in the same row of the dataframe (which gets us the number of correct answers), then divide it by the number of columns in the dataframe (which is the number of questions, or number of possible correct answers).