I create a labelled column with haven.
library(dplyr)
library(haven)
df <- tibble(x = labelled(c(1:3, NA), c('a' = 1, 'b' = 2, 'missing' = NA)))
# # A tibble: 4 × 1
# x
# <int+lbl>
# 1 1 [a]
# 2 2 [b]
# 3 3
# 4 NA
I seems that the missing value fails to be labelled. I expect to see somthing like
# # A tibble: 4 × 1
# x
# <int+lbl>
# 1 1 [a]
# 2 2 [b]
# 3 3
# 4 NA [missing]
In addition, as_factor gives
as_factor(df$x)
# [1] a b 3 <NA>
# Levels: a b 3 missing
but I want
# [1] a b 3 missing
# Levels: a b 3 missing
With
haven::tagged_na:Works as intended with
as_factor: