#' Rescale the Eurobarometer subjective urbanization variable
#'
#' Rescaling the Eurobarometer subjective urbanization variable.
#' @param column A column from a survey data with the subjective urbanization answers.
#' @param from Defaults to \code{c("NULL")} in which case the GESIS coding in English
#' \code{c("Rural area or village","Small or medium-sized town", "Large town/city")} will
#' be used.
#' @param to Defaults to \code{NULL} in which case the GESIS coding will be
#' shortened to \code{c("rural", "town", "city")}. If you choose \code{return_class = "numeric"}
#' the default \code{to} parameter changes to \code{c(0,1,2)}.
#' @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{"factor"}, alternatives \code{"character"} or
#' \code{"numeric"}.
#' @examples
#' rescale_subjective_urbanization (c("Rural area or village",
#' "Large town/city",
#' "Small or medium-sized town",
#' "DK"),
#' return_class = "numeric")
#'
#' ## Default return changes if the returned value is coded as numeric.
#'
#' rescale_subjective_urbanization (c("Rural area or village",
#' "Large town/city",
#' "Small or medium-sized town",
#' "DK"),
#' return_class = "numeric")
#'
#' @export
rescale_subjective_urbanization <- function ( column,
from = NULL,
to = NULL,
exact_from = TRUE,
na_labels = c("default"),
return_class = "factor") {
if (is.null(from)) {
from = c("Rural area or village",
"Small or medium-sized town",
"Large town/city")
}
if(is.null(to)) {
if ( return_class == "numeric") {
to = c(0,1,2)
} else {
to = c("rural", "town", "city")
}
}
return(rescale_categories(column = column,
from = from, to = to,
na_labels = na_labels,
exact_from = exact_from,
return_class = return_class))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.