unique_n | R Documentation |
Keep the first n unique elements in a vector
unique_n(vec, n, sort = "no")
vec |
(Vector) Any vector. |
n |
(Integer) The maximum number of elements to keep from |
sort |
(Character) |
A vector of the same type as vec
.
set.seed(12345)
lets <- sample(letters[1:10], 50, replace = TRUE)
unique_n(lets, 10, sort = "no")
## [1] "c" "j" "h" "b" "f" "g" "a" "d" "i" "e"
unique_n(lets, 8, sort = "asc")
## [1] "a" "b" "c" "d" "e" "f" "g" "h"
unique_n(lets, 5, sort = "desc")
## [1] "j" "i" "h" "g" "f"
unique_n(1:5, 20) # Asking for 20 elements, but there are only 5 uniques.
## [1] 1 2 3 4 5
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.