#' Rescale 4-level attachment level
#'
#' Rescale Eurobarometer 4-level attachment level,
#' \code{"Very attached"} and \code{"Fairly well attached"} and
#' \code{"Not very well attached"}, \code{"Not at all attached"}.
#' This is a wrapper function around the \code{\link{rescale_categories}} function.
#' @param column A column from a survey data frame where the level of
#' informnedss is recorded.
#' @param from Defaults \code{"Very attached"}, \code{"Fairly well attached"} and
#' \code{"Not very well attached"}, \code{"Not at all attached"}.
#' @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{("very_attached", "attached",
#' "not_very_attached", "not_attached")}.
#' @param na_labels Defaults to \code{"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_attachment_4 (column =
#' c("Very attached",
#' "Fairly well attached",
#' "Not very well attached",
#' "Not at all attached",
#' "DK", "NT/NV"),
#' na_labels = "default",
#' return_class = "character")
#'
#' rescale_attachment_4 (column =
#' c("Very attached",
#' "Fairly attached",
#' "Not well attached",
#' "Not at all attached",
#' "DK", "NT/NV"),
#' na_labels = "default",
#' return_class = "numeric")
#' @export
rescale_attachment_4 <- function ( column,
from = c("Very attached",
"Fairly attached",
"Not very attached",
"Not at all attached"),
to = c(2,1,-1,-2),
na_labels = "default",
underscore = TRUE,
exact_from = TRUE,
return_class = "numeric") {
if ( return_class %in% c("character", "factor")) {
to <- c("very_attached", "attached",
"not_very_attached", "not_attached")
if (underscore == FALSE) {
to <- gsub("_", " ", to)
}
}
return(surveyreader::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.