Convert input to a character vector

Share:

Description

By default, to_character is a wrapper for as.character. For labelled vector, to_character allows to specify if value, labels or labels prefixed with values should be used for conversion.

Usage

1
2
3
4
5
to_character(x, ...)

## S3 method for class 'labelled'
to_character(x, levels = c("labels", "values", "prefixed"),
  nolabel_to_na = FALSE, ...)

Arguments

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'?

Details

If some values doesn't have a label, automatic labels will be created, except if nolabel_to_na is TRUE.

Examples

1
2
3
4
5
v <- labelled(c(1,2,2,2,3,9,1,3,2,NA), c(yes = 1, no = 3, "don't know" = 9))
to_character(v)
to_character(v, missing_to_na = FALSE, nolabel_to_na = TRUE)
to_character(v, "v")
to_character(v, "p")