#' Rescale goals Eurobarometer question
#'
#' For example, to rescale the standard Eurobarometer EU 2020 goals variable(s) with
#' categories \code{"Too ambitious"}, \code{"About right"},
#' \code{"Too modest"}.
#' This is a wrapper function around the \code{\link{rescale_categories}} function.
#' @param column A column from a survey data frame where the situtation is recorded with
#' four categories.
#' @param from Defaults to \code{c("Very good", "Fairly good",
#' "Rather bad", "Very bad")}.
#' @param to Defaults to \code{c(-1,0,1)}. If \code{return_class = "character"} or
#' \code{return_class = "factor"} is selected it returns the abbreviated category
#' names \code{c("too_ambitious", "about_right", "too_modest"}.
#' @param na_labels Defaults to \code{"default"}.See \code{\link{rescale_categories}}.
#' @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_goal (
#' column = c("Too ambitious", "Too modest",
#' "Inap", "About right"),
#' return_class = "character",
#' underscore = FALSE)
#'
#' rescale_goal (c("Too ambitious", "Too modest",
#' "Inap", "About right"))
#' @export
rescale_goal <- function ( column,
from = c("Too ambitious",
"About right",
"Too modest"),
to = c(-1,0,1),
na_labels = "default",
return_class = "numeric",
underscore = TRUE) {
if ( return_class %in% c("character", "factor")) {
to = c("too_ambitious", "about_right", "too_modest")
}
if (underscore == FALSE) {
to = gsub("_", " ", to)
}
return(rescale_categories(column = column,
from = from, to = to,
na_labels = na_labels,
exact_from = TRUE,
return_class = return_class)
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.