length_by {quest}R Documentation

Length of a (Atomic) Vector by Group

Description

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 = ".")

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).

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.

See Also

lengths_by length agg

Examples


length_by(x = mtcars$"mpg", grp = mtcars$"gear")
length_by(x = airquality$"Ozone", grp = airquality$"Month", na.rm = FALSE)
length_by(x = airquality$"Ozone", grp = airquality$"Month", na.rm = TRUE)


[Package quest version 0.2.0 Index]