groupby_lag | R Documentation |
Cuts down on typing to preform relatively common functions.
groupby_lag( .data, ..., lagCol, newCol, n = 1L, order_by = NULL, default = NA, doUngroup = TRUE ) groupby_lead( .data, ..., leadCol, newCol, n = 1L, order_by = NULL, default = NA, doUngroup = TRUE )
.data |
data.frame/tibble |
... |
group_by fields past to group_by |
lagCol, leadCol |
what column in .data should be lagged or lead |
newCol |
name of column that the mutation creates |
n |
Positive integer of length 1, giving the number of positions to lead or lag by |
order_by |
Override the default ordering to use another vector or column |
default |
Value used for non-existant rows. Defaults to NA. |
doUngroup |
Ungroup the data? TRUE/FALSE. Default TRUE |
tibble
## Not run: df <- tibble::tribble( ~x, ~y, ~z, 'A', 3, 90, 'B', 3, 150, 'B', 2, 123, 'A', 1, 125, 'C', 1, 111, 'C', 2, 133, 'B', 1, 121, 'A', 2, 108, 'C', 3, 125 ) groupby_lag(df, x, lagCol = z, newCol = "test", n = 1, order_by = y) %>% dplyr::arrange(x, y) groupby_lag(df, x, lagCol = z, newCol = "test", n = 1) %>% dplyr::arrange(x) groupby_lead(df, x, leadCol = z, newCol = "test", n = 1, order_by = y) %>% dplyr::arrange(x, y) groupby_lead(df, x, leadCol = z, newCol = "test", n = 1) %>% dplyr::arrange(x) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.