Skip to content

Instantly share code, notes, and snippets.

@seasmith
Created April 16, 2020 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seasmith/07971958efabf77d705685688197cc7a to your computer and use it in GitHub Desktop.
Save seasmith/07971958efabf77d705685688197cc7a to your computer and use it in GitHub Desktop.
Last value per group
# Produces an 'unmatched length' error
last_by_group <- function (x, group = NULL, order_by = NULL, default = default_missing(x)) {
if (is.null(group)) {
return(last(x, order_by = order_by, default, default))
} else {
tapply(X = x, INDEX = group, FUN = last)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment