#' Rescale level yes-no four levels
#'
#' This is a wrapper function around the \code{\link{rescale_categories}} function.
#' @param column A column from a survey data with a four-level agreement scale.
#' @param from Defaults to \code{c("Yes, definitely", "Yes, to some extent",
#'"No, not really", "No, definitely not")}.
#' @param to Defaults to \code{c(2,1,-1,2)} ) If \code{return_class = "character"} or
#' \code{return_class = "factor"} is selected it returns the abbreviated category
#' names \code{c("definitely", "maybe",
#' "maybe_not", "definitely_not")}.
#' @param na_labels Defaults to \code{c("DK")}.
#' @param exact_from Deafults to \code{TRUE}. If \code{FALSE} you can use the
#' partial matching, but beware that in this case, \code{"twenty"} will be replaced by
#' @param underscore Defaults to \code{TRUE} in which case factor names or character strings
#' contain underscore_between_words. This is a better approach for further programming,
#' but you can choose \code{FALSE} for nicer printing results. See examples.
#' @param return_class Default is \code{"numeric"}, alternatives \code{"character"} or
#' \code{"factor"}.
#' @examples
#' rescale_yes_no_4 (c("Yes, definitely", "Yes, to some extent",
#' "No, not really", "No, definitely not", "Missing"),
#' na_labels = "Missing")
#'
#' @export
rescale_yes_no_4 <- function ( column,
from = c("Yes, definitely",
"Yes, to some extent",
"No, not really",
"No, definitely not"),
to = c(2,1,-1,-2),
na_labels = c("DK"),
underscore = TRUE,
exact_from = TRUE,
return_class = "numeric") {
if ( return_class %in% c("character", "factor")) {
to <- c("definitely", "maybe",
"maybe_not", "definitely_not")
if (underscore == FALSE) {
to <- gsub("_", " ", to)
}
}
return(surveyreader::rescale_categories(column = column,
from = from, to = to,
na_labels = na_labels,
exact_from = exact_from,
return_class = return_class))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.