Learn R Programming

tidycomm (version 0.4.1)

setna_scale: Set specified values to NA in selected variables or entire data frame

Description

This function allows users to set specific values to NA in chosen variables within a data frame. It can handle numeric, character, and factor variables.

Usage

setna_scale(data, ..., value, name = NULL, overwrite = FALSE)

Value

A tdcmm model or a tibble.

Arguments

data

A tibble or a tdcmm model.

...

One or more variables where specified values will be set to NA. If no variables are provided, the function is applied to the entire data frame.

value

A value (or vector of values) that needs to be set to NA.

name

The name of the new variable(s). By default, this is the same name as the provided variable(s) but suffixed with _na.

overwrite

Logical. If TRUE, it overwrites the original variable(s). You cannot specify both 'name' and 'overwrite' parameters simultaneously.

See Also

Other scaling: categorize_scale(), center_scale(), dummify_scale(), minmax_scale(), recode_cat_scale(), reverse_scale(), z_scale()

Examples

Run this code
WoJ %>%
dplyr::select(autonomy_emphasis) %>%
setna_scale(autonomy_emphasis, value = 5)
WoJ %>%
dplyr::select(autonomy_emphasis) %>%
setna_scale(autonomy_emphasis, value = 5, name = "new_na_autonomy")
WoJ %>%
setna_scale(value = c(2, 3, 4), overwrite = TRUE)
WoJ %>%
dplyr::select(country) %>% setna_scale(country, value = "Germany")
WoJ %>%
dplyr::select(country) %>% setna_scale(country, value = c("Germany", "Switzerland"))

Run the code above in your browser using DataLab