to_choice {exams.forge}R Documentation

Questions and Solutions List Generation

Description

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 a logical vector which contains TRUE if its value represents a correct answer and FALSE if it represents a wrong answer. The values can be shuffled or ordered (default).

If shuffle is a integer of length 1 then one correct answer is chosen, and shuffle wrong answers are chosen. If shuffle is a integer of length larger than 1, then shuffle[1] correct answers are chosen and shuffle[2] wrong answers are chosen. 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 for all values is applied.

The shuffling works in two steps:

  1. Sample within the correct and wrong value according to shuffle

  2. Apply shuffling (order=NULL) or ordering (default: order=order) of all selected answers

Usage

to_choice(
  df,
  correct,
  shuffle = c(NA_integer_, NA_integer_),
  orderfun = order,
  ...
)

choice_list(
  df,
  correct,
  shuffle = c(NA_integer_, NA_integer_),
  orderfun = order,
  ...
)

Arguments

df

vector or data frame: values, in a data frame each row holds one value

correct

logical: answer is correct (TRUE) or not (FALSE)

shuffle

integer: the numbers of correct and wrong values to shuffle (default: c(NA,NA)). NA means no shuffling

orderfun

function: ordering of the shuffled values (default: order)

...

further named parameters used in shuffle

Value

list with questions and solutions

Examples

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

[Package exams.forge version 1.0.10 Index]