By default, to_character is a wrapper for base::as.character().
For labelled vector, to_character allows to specify if value, labels or labels prefixed
with values should be used for conversion.
to_character(x, ...) # S3 method for haven_labelled to_character(x, levels = c("labels", "values", "prefixed"), nolabel_to_na = FALSE, ...)
| x | Object to coerce to a character vector. |
|---|---|
| ... | Other arguments passed down to method. |
| levels | What should be used for the factor levels: the labels, the values or labels prefixed with values? |
| nolabel_to_na | Should values with no label be converted to `NA`? |
If some values doesn't have a label, automatic labels will be created, except if
nolabel_to_na is TRUE.
#> [1] "yes" "2" "2" "2" "no" #> [6] "don't know" "yes" "no" "2" NAto_character(v, missing_to_na = FALSE, nolabel_to_na = TRUE)#> [1] "yes" NA NA NA "no" #> [6] "don't know" "yes" "no" NA NAto_character(v, "v")#> [1] "1" "2" "2" "2" "3" "9" "1" "3" "2" NAto_character(v, "p")#> [1] "[1] yes" "[2] 2" "[2] 2" "[2] 2" #> [5] "[3] no" "[9] don't know" "[1] yes" "[3] no" #> [9] "[2] 2" NA