length_by computes the the length of a (atomic) vector by group. The
argument na.rm can be used to include (FALSE) or exclude (TRUE)
missing values.
Usage
length_by(x, grp, na.rm = FALSE, sep = ".")
Value
integer vector of length = length(levels(interaction(grp)))
with names = length(levels(interaction(grp))) providing the number
of elements (excluding missing values if na.rm = TRUE) in each
group.
Arguments
x
atomic vector.
grp
atomic vector or list of atomic vectors (e.g., data.frame)
specifying the groups. The atomic vector(s) must be the length of x or else
an error is returned.
na.rm
logical vector of length 1 specifying whether to include (FALSE)
or exclude (TRUE) missing values.
sep
character vector of length 1 specifying what string should
separate different group values when naming the return object. This
argument is only used if grp is a list of atomic vectors (e.g.,
data.frame).