get_binary_score {capl} | R Documentation |
Compute a binary score.
Description
This function computes a binary score (0 = incorrect answer, 1 = correct answer) for a response to a questionnaire item based on the value(s) set as answer(s) to the item.
Usage
get_binary_score(x, answer)
Arguments
x |
A character or numeric vector representing a response to a questionnaire item. |
answer |
A character or numeric vector representing the correct answer(s) to the questionnaire item. The answer argument does not have to match x in case for a correct answer to be computed. |
Details
This function is called by get_fill_in_the_blanks_score()
.
Value
Returns 1 (if correct), 0 (if incorrect) or NA (if not valid).
Examples
get_binary_score(
x = c(1:4, NA, ""),
answer = 3
)
# [1] 0 0 1 0 NA 0
get_binary_score(
x = c("20 minutes", "30 minutes", "60 minutes or 1 hour", "120 minutes or 2 hours"),
answer = "60 minutes or 1 hour"
)
# [1] 0 0 1 0
get_binary_score(
x = c(1:5, "Heart", "hello, world", NA),
answer = c(3, "heart")
)
# [1] 0 0 1 0 0 1 0 NA
[Package capl version 1.42 Index]