to_choice: to_choice

View source: R/to_choice.R

to_choiceR Documentation

to_choice

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 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).

Usage

to_choice(
  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

Details

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:

  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

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

sigbertklinke/exams2moodle documentation built on July 6, 2023, 3:26 p.m.