R/rescale_description.R

#' Rescale description Eurobarometer questions
#'
#' Rescale the standard Eurobarometer outlook variable(s) with
#' categories \code{"Describes very well"}, \code{" Describes fairly well"},
#' \code{"Describes fairly badly"} and \code{"Describes very badly"}.
#' The generic question is \code{"In	general,	does	the	[EU]
#' conjure	up	for	you	a	very	positive,	fairly	positive,	neutral,
#' 	fairly	negative	or	very	negative	image?"}
#' 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{"Describes very well"}, \code{" Describes fairly well"},
#' \code{"Describes fairly badly"} and \code{"Describes very badly"}.
#' @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("very_positive", "fairly_positive", "fairly_negative",
#' "very_negative")}.
#' @param na_labels  Defaults to \code{c("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 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.
#' @examples
#' rescale_description (column =
#' c("Very well",
#'   "Fairly well",
#'   "Fairly badly",
#'   "Very badly",
#'   "DK", "NA"),
#' underscore = FALSE,
#' return_class = "character")
#'
#' rescale_description (column =
#' c("Very well",
#'   "Fairly well",
#'   "Fairly badly",
#'   "Very badly",
#'   "DK", "NA"),
#' return_class = "numeric")
#' @export

rescale_description <- function ( column,
                                 from = c("Very well",
                                          "Fairly well",
                                          "Fairly badly",
                                          "Very badly"),
                                 to = c(2,1,-1,-2),
                                 na_labels = "default",
                                 exact_from = TRUE,
                                 return_class = "numeric",
                                 underscore = TRUE) {


  if ( return_class %in% c("character", "factor")) {
    to = c("very_well", "fairly_well",
           "fairly_badly", "very_badly")
  }


  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.