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 : num 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.033521830 -0.489214026 -1.028169437 0.310835809 1.080984008 #> [6] 0.186740025 -0.004104253 1.019459431 -1.151478960 -0.009786653 #> [11] 0.198577688 0.684540653 -0.081271361 -0.006924049 -0.270495940 #> [16] -0.127314812 -0.450675910 -0.255239133 0.111597528 -0.351254628 #> [21] -0.477726076 -0.585710943 -0.727025190 -0.096506554 -0.305682265 #> [26] -0.561809361 0.857179159 0.194983468 -0.067084362 0.130067596 #> [31] -0.213378743 -0.091963570 0.561315920 -0.111306149 -0.361031207 #> [36] -0.242367684 1.274835781 -0.127851633 -0.263910556 -0.274003693 #> [41] -0.927901284 1.017808455 -0.886265267 -0.162162492 0.587376565 #> [46] -0.754100468 0.566094969 -0.220948596 1.028583311 -0.582840080 #> [51] 0.165262071 0.228629128 -0.629373066 -0.832428417 -0.235853871 #> [56] 0.606029106 0.804578053 -0.193818382 0.065907277 -0.457479365 #> [61] -0.138117281 0.989167581 0.133539814 0.155028258 0.409615917 #> [66] -0.162410026 0.574497417 0.164201118 -0.887644905 0.541568698 #> [71] 0.492000032 -0.155672293 0.594756415 1.154984921 1.832769460 #> [76] -0.518284857 -1.357618880 0.659036881 0.218730756 0.292376303 #> [81] 0.863148324 0.345660349 -0.249865799 0.327621845 -0.591421719 #> [86] 0.276967302 0.576863456 0.789108084 -0.302243166 0.194340764 #> [91] 0.212521642 -0.581899587 -0.058666692 1.178802069 0.885454676 #> [96] 0.297452459 -0.760231667 0.514904431 -0.254481278 0.145778019