Modelled on haven::zap_labels(), but more encompassing. By default removes the following attributes: format.spss, format.sas, format.stata, label, labels, na_values, na_range, display_width

zap_attributes(x, attributes = c("format.spss", "format.sas", "format.stata",
  "label", "labels", "na_values", "na_range", "display_width"))

Arguments

x

the data frame or variable

attributes

character vector of attributes to zap. NULL if everything (including factor levels etc) should be zapped

Examples

bfi <- data.frame(matrix(data = rnorm(300), ncol = 3)) names(bfi) <- c("bfi_e1", "bfi_e2R", "bfi_e3") attributes(bfi$bfi_e1)$label <- "I am outgoing." attributes(bfi$bfi_e2R)$label <- "I prefer books to people." attributes(bfi$bfi_e3)$label <- "I love to party." bfi$bfi_e <- rowMeans(bfi[, c("bfi_e1", "bfi_e2R", "bfi_e3")]) bfi <- detect_scales(bfi, quiet = TRUE) # create attributes str(zap_attributes(bfi, "label"))
#> 'data.frame': 100 obs. of 4 variables: #> $ bfi_e1 : num 0.2154 0.1924 -0.0188 1.0782 1.7582 ... #> $ bfi_e2R: num -0.5637 -1.4025 -2.3491 0.0793 1.2248 ... #> $ bfi_e3 : num 0.449 -0.258 -0.717 -0.225 0.26 ... #> $ bfi_e : atomic 0.0335 -0.4892 -1.0282 0.3108 1.081 ... #> ..- attr(*, "scale_item_names")= chr "bfi_e1" "bfi_e2R" "bfi_e3"
zap_attributes(bfi$bfi_e)
#> [1] 0.0335 -0.4892 -1.0282 0.3108 1.0810 0.1867 -0.0041 1.0195 -1.1515 #> [10] -0.0098 0.1986 0.6845 -0.0813 -0.0069 -0.2705 -0.1273 -0.4507 -0.2552 #> [19] 0.1116 -0.3513 -0.4777 -0.5857 -0.7270 -0.0965 -0.3057 -0.5618 0.8572 #> [28] 0.1950 -0.0671 0.1301 -0.2134 -0.0920 0.5613 -0.1113 -0.3610 -0.2424 #> [37] 1.2748 -0.1279 -0.2639 -0.2740 -0.9279 1.0178 -0.8863 -0.1622 0.5874 #> [46] -0.7541 0.5661 -0.2209 1.0286 -0.5828 0.1653 0.2286 -0.6294 -0.8324 #> [55] -0.2359 0.6060 0.8046 -0.1938 0.0659 -0.4575 -0.1381 0.9892 0.1335 #> [64] 0.1550 0.4096 -0.1624 0.5745 0.1642 -0.8876 0.5416 0.4920 -0.1557 #> [73] 0.5948 1.1550 1.8328 -0.5183 -1.3576 0.6590 0.2187 0.2924 0.8631 #> [82] 0.3457 -0.2499 0.3276 -0.5914 0.2770 0.5769 0.7891 -0.3022 0.1943 #> [91] 0.2125 -0.5819 -0.0587 1.1788 0.8855 0.2975 -0.7602 0.5149 -0.2545 #> [100] 0.1458