Examples for 'haven::tagged_na'


"Tagged" missing values

Aliases: tagged_na na_tag is_tagged_na format_tagged_na print_tagged_na

Keywords:

### ** Examples

x <- c(1:5, tagged_na("a"), tagged_na("z"), NA)

# Tagged NA's work identically to regular NAs
x
[1]  1  2  3  4  5 NA NA NA
is.na(x)
[1] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE
# To see that they're special, you need to use na_tag(),
# is_tagged_na(), or print_tagged_na():
is_tagged_na(x)
[1] FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE
na_tag(x)
[1] NA  NA  NA  NA  NA  "a" "z" NA 
print_tagged_na(x)
[1]     1     2     3     4     5 NA(a) NA(z)    NA
# You can test for specific tagged NAs with the second argument
is_tagged_na(x, "a")
[1] FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
# Because the support for tagged's NAs is somewhat tagged on to R,
# the left-most NA will tend to be preserved in arithmetic operations.
na_tag(tagged_na("a") + tagged_na("z"))
[1] "a"

[Package haven version 2.5.0 Index]