1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/verb-count.R
\name{count.tbl_lazy}
\alias{count.tbl_lazy}
\alias{add_count.tbl_lazy}
\alias{tally.tbl_lazy}
\title{Count observations by group}
\usage{
\method{count}{tbl_lazy}(x, ..., wt = NULL, sort = FALSE, name = NULL)
\method{add_count}{tbl_lazy}(x, ..., wt = NULL, sort = FALSE, name = NULL, .drop = NULL)
\method{tally}{tbl_lazy}(x, wt = NULL, sort = FALSE, name = NULL)
}
\arguments{
\item{x}{A data frame, data frame extension (e.g. a tibble), or a
lazy data frame (e.g. from dbplyr or dtplyr).}
\item{...}{<\code{\link[rlang:args_data_masking]{data-masking}}> Variables, or
functions of variables. Use \code{\link[dplyr:desc]{desc()}} to sort a variable in descending
order.}
\item{wt}{<\code{\link[rlang:args_data_masking]{data-masking}}> Frequency weights.
Can be \code{NULL} or a variable:
\itemize{
\item If \code{NULL} (the default), counts the number of rows in each group.
\item If a variable, computes \code{sum(wt)} for each group.
}}
\item{sort}{If \code{TRUE}, will show the largest groups at the top.}
\item{name}{The name of the new column in the output.
If omitted, it will default to \code{n}. If there's already a column called \code{n},
it will use \code{nn}. If there's a column called \code{n} and \code{nn}, it'll use
\code{nnn}, and so on, adding \code{n}s until it gets a new name.}
\item{.drop}{Not supported for lazy tables.}
}
\description{
These are methods for the dplyr \code{\link[=count]{count()}} and \code{\link[=tally]{tally()}} generics. They
wrap up \code{\link[=group_by.tbl_lazy]{group_by.tbl_lazy()}}, \code{\link[=summarise.tbl_lazy]{summarise.tbl_lazy()}} and, optionally,
\code{\link[=arrange.tbl_lazy]{arrange.tbl_lazy()}}.
}
\examples{
library(dplyr, warn.conflicts = FALSE)
db <- memdb_frame(g = c(1, 1, 1, 2, 2), x = c(4, 3, 6, 9, 2))
db \%>\% count(g) \%>\% show_query()
db \%>\% count(g, wt = x) \%>\% show_query()
db \%>\% count(g, wt = x, sort = TRUE) \%>\% show_query()
}
|