R/rescale_trust.R

#' Rescale trust institutions question
#'
#' Rescale Eurobarometer trust in institutions variable with two levels,
#' \code{"Tend to trust"} and \code{"Tend not to trust"}.
#' This is a wrapper function around the \code{\link{rescale_categories}} function.
#' @param column A column from a survey data frame where trust in an institution
#' is recorded.
#' @param from Defaults to \code{c("Tend to trust", "Tend not to trust")}.
#' @param to Defaults to \code{c(1,0)}. If  \code{return_class = "character"} or
#' \code{return_class = "factor"} is selected it returns the abbreviated category
#' names \code{c("trust", "distrust")}.
#' @param na_labels  Defaults to \code{"default"}.
#' @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 return_class Default is \code{"numeric"}, alternatives \code{"character"} or
#' \code{"factor"}.
#' @param messages Defaults to \code{FALSE}. Hides missing factor value messages.
#' @examples
#' rescale_direction (column =
#'    c("Things are going in the right direction",
#'      "Things are going in the wrong direction",
#'      "Neither one nor the other (SPONTANEOUS)",
#'      "DK"),
#'      na_labels = "DK")
#' @export

rescale_trust <- function ( column,
                                 from = c("Tend to trust",
                                          "Tend not to trust"),
                                 to = c(1,0),
                                 na_labels = "default",
                                 exact_from = TRUE,
                                 return_class = "numeric",
                                 messages = FALSE) {
  if ( return_class %in% c("character", "factor")) {
    to = c("trust", "distrust")
  }

  return(rescale_categories(column = column,
                            from = from, to = to,
                            na_labels = na_labels,
                            exact_from = exact_from,
                            return_class = return_class))

}
antaldaniel/surveyreader documentation built on May 16, 2019, 2:29 a.m.