Hi, all.
I am trying to use tidyverse functions to create a function that applies a scoring key, for multiple-choice question (MCQ) data, to a tibble. I can apply the scoring key to each column, where each column is an MCQ on a test, but the output is always transposed! Any ideas about how to apply the key to a tibble and then return a tibble that isn't transposed in any funky way? Here's where I'm at so far.
key <- c("A", "B", "C", "C") # The answers to each MCQ below
df <- tibble(
I1 = sample( LETTERS[1:4], 4, replace = T),
I2 = sample( LETTERS[1:4], 4, replace = T),
I3 = sample( LETTERS[1:4], 4, replace = T),
I4 = sample( LETTERS[1:4], 4, replace = T)
)
df1 <- df %>% mutate_all( # The scores end up transposed here
function( x) {
if_else( x == key, 1, 0)
}
)
df1