If you have or can construct a data frame in the following form, where id
represents students and A
, B
and C
represent whether those questions were answered,
set.seed(42)
d <- data.frame(id = 1:20,
A = sample(c(TRUE,FALSE),20, replace = TRUE),
B = sample(c(TRUE,FALSE),20, replace = TRUE),
C = sample(c(TRUE,FALSE),20, replace = TRUE))
then, add a column score
to indicate if at least one of A
, B
or C
was answered (TRUE
)
set.seed(42)
d <- data.frame(id = 1:20,
A = sample(c(TRUE,FALSE),20, replace = TRUE),
B = sample(c(TRUE,FALSE),20, replace = TRUE),
C = sample(c(TRUE,FALSE),20, replace = TRUE))
d$score <- ifelse(rowSums(d[2:4]) > 0,TRUE,FALSE)
d
#> id A B C score
#> 1 1 TRUE TRUE TRUE TRUE
#> 2 2 TRUE TRUE TRUE TRUE
#> 3 3 TRUE TRUE FALSE TRUE
#> 4 4 TRUE TRUE FALSE TRUE
#> 5 5 FALSE TRUE FALSE TRUE
#> 6 6 FALSE FALSE FALSE FALSE
#> 7 7 FALSE TRUE FALSE TRUE
#> 8 8 FALSE TRUE FALSE TRUE
#> 9 9 TRUE TRUE FALSE TRUE
#> 10 10 FALSE TRUE TRUE TRUE
#> 11 11 TRUE FALSE FALSE TRUE
#> 12 12 FALSE FALSE TRUE TRUE
#> 13 13 TRUE FALSE FALSE TRUE
#> 14 14 FALSE FALSE FALSE FALSE
#> 15 15 TRUE TRUE FALSE TRUE
#> 16 16 TRUE FALSE FALSE TRUE
#> 17 17 FALSE TRUE TRUE TRUE
#> 18 18 FALSE FALSE FALSE FALSE
#> 19 19 FALSE FALSE TRUE TRUE
#> 20 20 FALSE FALSE TRUE TRUE
Created on 2023-03-01 with reprex v2.0.2