% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/count.r
\name{count}
\alias{count}
\title{Count the number of occurences.}
\usage{
count(df, vars = NULL, wt_var = NULL)
}
\arguments{
\item{df}{data frame to be processed}

\item{vars}{variables to count unique values of}

\item{wt_var}{optional variable to weight by - if this is non-NULL, count
will sum up the value of this variable for each combination of id
variables.}
}
\value{
a data frame with label and freq columns
}
\description{
Equivalent to \code{as.data.frame(table(x))}, but does not include
combinations with zero counts.
}
\details{
Speed-wise count is competitive with \code{\link{table}} for single
variables, but it really comes into its own when summarising multiple
dimensions because it only counts combinations that actually occur in the
data.

Compared to \code{\link{table}} + \code{\link{as.data.frame}}, \code{count}
also preserves the type of the identifier variables, instead of converting
them to characters/factors.
}
\examples{
# Count of each value of "id" in the first 100 cases
count(baseball[1:100,], vars = "id")
# Count of ids, weighted by their "g" loading
count(baseball[1:100,], vars = "id", wt_var = "g")
count(baseball, "id", "ab")
count(baseball, "lg")
# How many stints do players do?
count(baseball, "stint")
# Count of times each player appeared in each of the years they played
count(baseball[1:100,], c("id", "year"))
# Count of counts
count(count(baseball[1:100,], c("id", "year")), "id", "freq")
count(count(baseball, c("id", "year")), "freq")
}
\seealso{
\code{\link{table}} for related functionality in the base package
}
\keyword{manip}
