Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count function #358

Closed
hadley opened this issue Mar 26, 2014 · 1 comment
Closed

Count function #358

hadley opened this issue Mar 26, 2014 · 1 comment
Assignees
Labels
feature a feature request or enhancement
Milestone

Comments

@hadley
Copy link
Member

hadley commented Mar 26, 2014

Maybe something like this:

count <- function(tbl, ..., wt = NULL) {
  vars <- dots(...)
  wt <- substitute(wt)

  grouped <- regroup(tbl, vars)
  if (is.null(wt)) {
    summarise(grouped, n = n())
  } else {
    call <- substitute(summarise(grouped, n = sum(wt)), list(wt = wt))
    eval(call)
  }
}
@hadley hadley added this to the v0.2 milestone Mar 26, 2014
@hadley hadley modified the milestones: 0.3, v0.2 Apr 7, 2014
@hadley hadley self-assigned this Aug 1, 2014
@hadley
Copy link
Member Author

hadley commented Sep 23, 2014

Should be something like this:

count <- function(tbl, ..., wt = NULL, sort = FALSE) {
  vars <- lazyeval::dots(...)
  wt <- substitute(wt)

  count_(tbl, vars, wt, sort = sort)
}

count_ <- function(tbl, ..., wt = NULL, sort = FALSE) {
  grouped <- group_by_(tbl, vars)
  tally_(grouped, wt = wt, sort = sort)  
}

@hadley hadley closed this as completed in dc92c24 Sep 25, 2014
krlmlr pushed a commit to krlmlr/dplyr that referenced this issue Mar 2, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant