Learn R Programming

labelled (version 2.11.0)

unique_tagged_na: Unique elements, duplicated, ordering and sorting with tagged NAs

Description

These adaptations of base::unique(), base::duplicated(), base::order() and base::sort() treats tagged NAs as distinct values.

Usage

unique_tagged_na(x, fromLast = FALSE)

duplicated_tagged_na(x, fromLast = FALSE)

order_tagged_na( x, na.last = TRUE, decreasing = FALSE, method = c("auto", "shell", "radix"), na_decreasing = decreasing, untagged_na_last = TRUE )

sort_tagged_na( x, decreasing = FALSE, na.last = TRUE, na_decreasing = decreasing, untagged_na_last = TRUE )

Arguments

x

a vector

fromLast

logical indicating if duplication should be considered from the last

na.last

if TRUE, missing values in the data are put last; if FALSE, they are put first

decreasing

should the sort order be increasing or decreasing?

method

the method to be used, see base::order()

na_decreasing

should the sort order for tagged NAs value be

untagged_na_last

should untagged NAs be sorted after tagged NAs? increasing or decreasing?

Examples

Run this code
x <- c(1, 2, tagged_na("a"), 1, tagged_na("z"), 2, tagged_na("a"), NA)
x %>% print_tagged_na()

unique(x) %>% print_tagged_na()
unique_tagged_na(x) %>% print_tagged_na()

duplicated(x)
duplicated_tagged_na(x)

order(x)
order_tagged_na(x)

sort(x, na.last = TRUE) %>% print_tagged_na()
sort_tagged_na(x) %>% print_tagged_na()

Run the code above in your browser using DataLab