Skip to contents

Harmonize the na_values attribute with na_range, if the latter is present.

Usage

na_range_to_values(x)

is.na_range_to_values(x)

Arguments

x

A labelled_spss or labelled_spss_survey vector

Value

A x with harmonized na_values and na_range attributes. If min(na_values) or max(na_values) than the left- and right-hand value of na_range, it gives a warning and adjusts the original na_range.

Details

na_range_to_values() tests if the function needs to be called for na_values harmonization. The na_range is often missing and less likely to cause logical problems when joining survey answers.

See also

Other variable label harmonization functions: label_normalize()

Examples

var1 <- labelled::labelled_spss(
  x = c(1,0,1,1,0,8,9), 
  labels = c("TRUST" = 1, 
             "NOT TRUST" = 0, 
             "DON'T KNOW" = 8, 
             "INAP. HERE" = 9), 
na_range = c(8,12))
  
na_range_to_values(var1)
#> <labelled_spss<double>[7]>
#> [1] 1 0 1 1 0 8 9
#> Missing values: 8, 9
#> Missing range:  [8, 12]
#> 
#> Labels:
#>  value      label
#>      1      TRUST
#>      0  NOT TRUST
#>      8 DON'T KNOW
#>      9 INAP. HERE
as_numeric(na_range_to_values(var1))
#> [1]  1  0  1  1  0 NA NA
as_character(na_range_to_values(var1))
#> [1] "TRUST"      "NOT TRUST"  "TRUST"      "TRUST"      "NOT TRUST" 
#> [6] "DON'T KNOW" "INAP. HERE"