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

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")
)

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.105 -0.254 -0.976 0.394 1.015 ... #> $ bfi_e2R: num -0.5175 -0.2596 -0.3281 0.0734 -0.2479 ... #> $ bfi_e3 : num -0.0946 -0.074 0.7145 0.1247 1.2966 ... #> $ bfi_e : num -0.169 -0.196 -0.197 0.197 0.688 ... #> ..- attr(*, "scale_item_names")= chr [1:3] "bfi_e1" "bfi_e2R" "bfi_e3"
zap_attributes(bfi$bfi_e)
#> [1] -0.16890812 -0.19578154 -0.19668841 0.19745618 0.68787811 -0.61897046 #> [7] -0.45530096 -0.86969664 0.17813778 -0.14167868 0.26362477 -0.84599378 #> [13] 0.46032436 -0.47602042 0.06687563 -0.44469117 1.00128606 -0.95524539 #> [19] -0.24014184 -0.78531245 -0.47150749 -0.80184033 0.99727471 -0.03043471 #> [25] 0.47689599 -0.61384304 -0.69128843 -0.13122497 0.24865902 0.33993063 #> [31] -0.30801029 1.30520813 -0.31697139 -0.57792328 -0.36195160 -0.32719319 #> [37] 0.13682951 0.05335115 0.50274183 -0.13673690 -0.02931476 -0.17125795 #> [43] -0.72538076 0.12078085 -0.49113367 0.66298692 0.18046936 0.10825898 #> [49] -0.09677067 0.33776731 1.08638577 0.45076696 -0.29749582 0.06707868 #> [55] -0.41926556 0.32954947 -0.09538570 0.97246318 0.81898326 -0.39362951 #> [61] 0.31227753 0.31005410 -0.20214129 -0.34713210 0.60629464 -0.57121456 #> [67] 0.53569440 -0.45018676 0.19141873 -0.46629549 -0.21009392 0.70738451 #> [73] -0.52281520 0.01417126 -0.15758700 -0.62898441 -0.40923643 0.70690023 #> [79] 0.99421047 -0.25121701 0.51109272 1.16888779 1.00454045 -0.66665345 #> [85] -0.13669536 0.18895865 0.08757627 1.06423954 0.66083123 0.84815936 #> [91] -0.49123552 0.47051765 0.58646209 -0.70425772 0.95421308 0.86075540 #> [97] 0.72797462 0.47609657 -0.34513801 0.02850471
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 1.38 -0.7 1.86 1.8 -1.36 ... #> $ bfi_e2R: num 1.277 0.821 0.42 1.712 -2.216 ... #> $ bfi_e3 : num -1.696 0.683 1.362 1.906 -0.673 ... #> $ bfi_e : num 0.322 0.268 1.214 1.807 -1.415 ... #> ..- attr(*, "scale_item_names")= chr [1:3] "bfi_e1" "bfi_e2R" "bfi_e3"
zap_attributes(bfi$bfi_e)
#> [1] 0.32161787 0.26786411 1.21409288 1.80718065 -1.41483825 -0.52084690 #> [7] 0.42852874 -0.28885318 -0.13282287 0.26231051 0.33037732 -0.66239671 #> [13] -0.41755859 -0.07060293 0.03819649 -0.01860240 -0.41380651 0.25683774 #> [19] 1.22431718 0.65738486 0.34206506 0.53682910 -0.36566688 0.28020371 #> [25] -0.05995920 0.55770585 0.47785912 -0.52293270 -0.39808839 0.00767314 #> [31] 0.59391091 1.43475255 -0.58553708 -0.28708600 -0.76909881 0.31998228 #> [37] 0.71857598 -0.48310841 -0.36102428 0.21083309 0.84933711 0.59996355 #> [43] -0.30237323 0.00459864 -0.87617110 -0.16264165 0.69489642 -0.33928308 #> [49] 0.27599683 0.16165674 0.21767609 0.47162477 0.20924933 -0.69340872 #> [55] -0.32725773 -1.18627366 -0.34040522 1.13186682 -0.89911617 -0.06716810 #> [61] 0.27562846 -0.39806501 -0.92354995 -0.04789468 0.60188788 0.12761961 #> [67] -0.29388311 -0.26866617 0.88746566 0.20392017 0.03406801 -0.70086223 #> [73] 0.24546147 -0.68881117 0.30372659 -0.77161868 0.36651513 -0.07598943 #> [79] -0.41116337 0.08225432 0.63725203 1.26537240 0.20893318 0.62405874 #> [85] -0.14711103 0.32219136 -0.32570856 0.23811886 -0.95617717 -0.96482800 #> [91] 0.71592173 -0.22022941 0.43144485 0.29196733 0.46192271 0.06199001 #> [97] 0.70562634 -0.25835902 -0.09774164 0.68020002