Description Usage Arguments Examples
View source: R/group_numeric.R
Mutate a dataframe by assigning each row a group based on its value in a certain column.
1 | group_numeric(df, col, vec, add_first_last = FALSE)
|
df |
A dataframe |
col |
A numeric or date column. If the value here is outside the vector range, the 'group' colum will be set to NA for that row. |
vec |
A vector of cuts. |
add_first_last |
Should the first and last element of the vector be used as the lower and upper bounds, respectively, for the 1st and nth element? Or should those In other words, should the 1st element of the vector be considered the lower (add_first_last = FALSE) or upper (add_first_last = TRUE) bound of the first group? |
1 2 3 4 5 6 | mpg_cuts <- c(15, 20, 25, 30)
group_numeric(mtcars, "mpg", mpg_cuts, add_first_last = TRUE)
mtcars$some_dates <- (rnorm(n = 32) * 5) %>% lubridate::as_date()
date_cuts <- c("1969-11-01", "1969-12-29", "1970-01-01", "1970-01-04", "1970-02-01")
group_numeric(mtcars, "some_dates", date_cuts, add_first_last = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.