to_choice | R Documentation |
Creates a list with the elements questions
and solutions
values. A value can be either an entry in a vector or
a row in a data frame. correct
is logical vectors which contains TRUE
if the values represents a correct answer
and FALSE
if it represents a wrong answer. The values can be shuffled or ordered (default).
to_choice(
df,
correct,
shuffle = c(NA_integer_, NA_integer_),
orderfun = order,
...
)
df |
vector or data frame: values, in a data frame each row holds one value |
correct |
logical: answer is correct ( |
shuffle |
integer: the numbers of correct and wrong values to shuffle (default: |
orderfun |
function: ordering of the shuffled values (default: |
... |
further named parameters used in |
If shuffle
is a integer of length 1 then one correct answer is choosen and shuffle
wrong answers are choosen.
If shuffle
is a integer of length larger than 1 then shuffle[1]
correct answers are choosen and shuffle[2]
wrong answers are choosen.
If any shuffle
entry is zero or negative then no shuffling will be done.
If order
is a function then it is expected that the function delivers an index for the reordering of the values.
Otherwise a shuffle about all values is applied.
The shuffling works in two steps:
Sample within the correct and wrong value according to shuffle
Apply shuffling (order=NULL
) or ordering (default: order=order
) of all selected answers
list with questions and solutions
answer <- runif(5)
correct <- (1:5)==3 # third answer is correct, the rest wrong
sc <- to_choice(answer, correct)
str(sc) # answers are ordered by size
sc$questions <- c(format(sc$questions, nsmall=2), "No answer is correct") # Additional answer
sc$solutions <- c(sc$solutions, FALSE) # TRUE or FALSE?
sc <- to_choice(answer, correct, shuffle=2)
str(sc) # one correct answer and two wrong answers selected
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.