Removes value labels, leaving unlabelled vectors as is. Use this if you
want to simply drop all labels
from a data frame.
Zapping labels from labelled_spss()
also removes user-defined missing
values by default, replacing with standard NA
s. Use the user_na
argument
to override this behaviour.
Arguments
- x
A vector or data frame
- ...
Other arguments passed down to method.
- user_na
If
FALSE
, the default,zap_labels()
will convertlabelled_spss()
user-defined missing values toNA
. IfTRUE
they will be treated like normal values.
See also
zap_label()
to remove variable labels.
Other zappers:
zap_empty()
,
zap_formats()
,
zap_label()
,
zap_widths()
Examples
x1 <- labelled(1:5, c(good = 1, bad = 5))
x1
#> <labelled<integer>[5]>
#> [1] 1 2 3 4 5
#>
#> Labels:
#> value label
#> 1 good
#> 5 bad
zap_labels(x1)
#> [1] 1 2 3 4 5
x2 <- labelled_spss(c(1:4, 9), c(good = 1, bad = 5), na_values = 9)
x2
#> <labelled_spss<double>[5]>
#> [1] 1 2 3 4 9
#> Missing values: 9
#>
#> Labels:
#> value label
#> 1 good
#> 5 bad
zap_labels(x2)
#> [1] 1 2 3 4 NA
# Keep the user defined missing values
zap_labels(x2, user_na = TRUE)
#> [1] 1 2 3 4 9
# zap_labels also works with data frames
df <- tibble::tibble(x1, x2)
df
#> # A tibble: 5 × 2
#> x1 x2
#> <int+lbl> <dbl+lbl>
#> 1 1 [good] 1 [good]
#> 2 2 2
#> 3 3 3
#> 4 4 4
#> 5 5 [bad] 9 (NA)
zap_labels(df)
#> # A tibble: 5 × 2
#> x1 x2
#> <int> <dbl>
#> 1 1 1
#> 2 2 2
#> 3 3 3
#> 4 4 4
#> 5 5 NA