only | R Documentation |
Extracts the only distinct value from an atomic vector or throws an informative error if no values or multiple distinct values.
only(x, na_rm = FALSE)
x |
An atomic vector. |
na_rm |
A flag indicating whether to exclude missing values. |
only()
is useful when summarizing a vector by group
while checking the assumption that it is constant within the group.
The only distinct value from a vector otherwise throws an error.
dplyr::first()
only(c(1, 1))
only(c(NA, NA))
only(c(1, 1, NA), na_rm = TRUE)
try(only(character(0)))
try(only(c(1, NA)))
try(only(c(1, 2)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.