If unique(x) is a single value, return it; otherwise, return an NA of the same type as x. If x is a factor, then the levels and ordered status will be kept in either case. If x is a non-atomic vector (i.e. a list), then the logical NA will be used.

unique_or_na(x)

Arguments

x

A vector

Examples

f <- factor(c("a", "a", "b", "c"), ordered = TRUE) unique_or_na(f)
#> Error in unique_or_na(f): could not find function "unique_or_na"
unique_or_na(f[1:2])
#> Error in unique_or_na(f[1:2]): could not find function "unique_or_na"
x <- c("a", "b", "a") unique_or_na(x[c(1, 3)])
#> Error in unique_or_na(x[c(1, 3)]): could not find function "unique_or_na"
unique_or_na(x)
#> Error in unique_or_na(x): could not find function "unique_or_na"
unique_or_na(x) %>% typeof
#> Error in unique_or_na(x): could not find function "unique_or_na"