R/rescale_difficulty.R

#' Rescale difficulty
#'
#' Create a uniform variable from three categories of the Eurobarometer
#' subjective living condition trend variable with categories such as
#' \code{"Most of the time"}, \code{"From time to time"} and
#' \code{"Almost never/never".} This is a wrapper function around the
#' \code{\link{rescale_categories}} function.
#' @param column A column from a survey data frame where gender is recorded.
#' @param from Defaults to \code{c("Most of the time", "From time to time", "Almost never/never"}.
#' @param to Defaults to \code{c(2,1,0)}.
#' @param na_labels  Defaults to \code{c("NA","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 return_class Default is \code{"numeric"}, alternatives \code{"character"} or
#' \code{"factor"}.
#' @importFrom haven as_factor
#' @importFrom plyr mapvalues
#' @importFrom stringr str_trim
#' @examples
#' rescale_difficulty (column =
#'                       c("Most of the time", "From time to time",
#'                         "Almost never/never", "MOST of the TIME", "Refusal (SPONT.)", NA),
#'                     na_labels = "Refusal (SPONT.)")
#' @export

rescale_difficulty <- function ( column,
                          from = c("Most of the time", "From time to time",
                                   "Almost never/never"),
                          to = c(2,1,0),
                          na_labels = c("NA", "DK"),
                          exact_from = TRUE,
                          return_class = "numeric") {

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

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