View source: R/split_at_percentile.R
split_at_percentile | R Documentation |
Factorizes a vector by percentiles
split_at_percentile(
x,
frac = c(1/3, 2/3),
labels = c("low", "middle", "high"),
type = "higher",
explicit_na = NA
)
x |
A vector |
frac |
Fractions to split at (e.g., |
labels |
Vector with factor labels. |
type |
"higher" will split group below fraction and last group equal above last fraction. and "lower" will split group below fraction (vs. equal and above) |
explicit_na |
If not NA, NAs will be recoded as a factor level of the provided name. If TRUE, the name will default to '(Missing)'. |
A vector of type factor with two levels.
x <- sample(c(1:10, NA), 100, replace = TRUE)
x <- split_at_percentile(x, explicit_na = TRUE)
table(x)
split_at_percentile(
1:100,
frac = c(0.25, 0.5, 0.75),
labels = c("0-24", "25-49", "50-74", "75-100")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.