R/rescale_benefit_2.R

#' Rescale outlook Eurobarometer questions
#'
#' Rescale the standard Eurobarometer candidate membership
#' benefit variable(s) with
#' categories \code{"Would	benefit"}, \code{"Would	not	benefit"}.
#' The generic question is \code{"Taking	everything	into	account,
#' 	would	you	say	that	(OUR	COUNTRY)	would	benefit	or	not	from
#' being	a	member	of	the	EU?"}
#' 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{"Would	benefit"}, \code{"Would	not	benefit"}.
#' @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("benefit", "not_benefit"}.
#' @param na_labels  Defaults to \code{c("default")}.
#' @param exact_from Deafults to \code{TRUE}.
#' @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_benefit_2 (column =c("DK",
#'                              "Would benefit",
#'                              "Would not benefit"),
#'                    return_class = "character",
#'                    underscore = FALSE)
#'
#' rescale_benefit_2 (column =c("DK","Would benefit",
#'                              "Would not benefit"),
#'                    return_class = "numeric")
#' @export

rescale_benefit_2 <- function ( column,
                                 from = c("Would benefit",
                                          "Would not benefit"),
                                 to = c(1,0),
                                 na_labels = "default",
                                 exact_from = TRUE,
                                 return_class = "numeric",
                                 underscore = TRUE) {


  if ( return_class %in% c("character", "factor")) {
    to <- c("benefit", "not_benefit")
    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.