R/rescale_goal_3.R

#' Rescale 3-level goal evaluation.
#'
#' Rescale 3-level categorical variables
#' \code{"Too modest"}, \code{"About right"} and \code{"Too ambitious"}.
#' This is a wrapper function around the the \code{\link{rescale_categories}} function.
#' @param column A column from a survey data frame where
#' the evaluation of goals takes place with three levels.
#' @param from Defaults to \code{c("modest", "right", "ambitious")}.
#' @param to Defaults to \code{c(1,0,-1)} )
#' @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 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_goal_3 (column = c(
#'  "Too modest", "About RIGHT", "Too ambitious", "NA", "DK")
#'  )
#' @export

rescale_goal_3 <- function ( column,
                          from = c("Too modest",
                                   "About right",
                                   "Too ambitious"),
                          to = c(1,0,-1),
                          na_labels = c("NA","DK"),
                          underscore = TRUE,
                          exact_from = TRUE,
                          return_class = "numeric" ) {
  if ( return_class %in% c("character", "factor")) {
    to <- c("modest", "right", "ambitious")
    if (underscore == FALSE) {
      to <- gsub("_", " ", to)
    }
  }

  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.