R/triad.gen.R

Defines functions triad.gen

Documented in triad.gen

#' triad.gen
#' Create triad test instrument
#' @alias triad.gen
#' @usage triad.gen(items)
#' @examples
#' @param items This is a list of the items you'll use in your instrument.
#' @return The output of this function is a randomize ready-to-use triad test.
#' @author Benjamin Grant Purzycki. <bgpurzycki@@cas.au.dk>
#' RVS <- c("Ben", "Uffe", "Jesper", "Lene", "Jorn", "Marianne Q.-F.", "Thomas", "Martin", "Mark") # your items
#' triadmat <- triad.gen(RVS)
#' View(triadmat)
#' @export
#' @examples
#' RVS <- c("Ben", "Uffe", "Jesper", "Lene", "Jorn", "Marianne Q.-F.", "Thomas", "Martin", "Mark") # your items
#' triadmat <- triad.gen(RVS)
#' View(triadmat)
#' 

triad.gen <- function(items){
  triadlist <- data.frame(t(combn(items, 3))) # all possible triad combs
  triadlist$NUM <- seq(1, nrow(triadlist), 1) # assign triad a number
  triadlist <- triadlist[, c(4, 1, 2, 3)] # rearrange variable order
  triadlist$rand <- sample(1:nrow(triadlist), nrow(triadlist), replace = F)
  triadlist <- triadlist[order(triadlist$rand),] # randomize!
  return(triadlist)
}
alastair-JL/AnthroTools documentation built on Aug. 29, 2024, 9:36 a.m.