View source: R/diary_functions.R
lengths_by | R Documentation |
lengths_by
computes the the length of multiple columns in a data.frame
by group. The argument na.rm
can be used to include (FALSE) or exclude
(TRUE) missing values. Through the use of na.rm
= TRUE, the number of
observed values for each variable by each group can be computed.
lengths_by(data, vrb.nm, grp.nm, na.rm = FALSE, sep = ".")
data |
data.frame of data. |
vrb.nm |
character vector of colnames from |
grp.nm |
character vector of colnames from |
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). |
data.frame with colnames = vrb.nm
and rownames =
length(levels(interaction(grp)))
providing the number of elements
(excluding missing values if na.rm
= TRUE) in each column by group.
length_by
length
colNA
lengths_by(mtcars, vrb.nm = c("mpg","cyl","disp"), grp = "gear")
lengths_by(mtcars, vrb.nm = c("mpg","cyl","disp"),
grp = c("gear","vs")) # can handle multiple grouping variables
lengths_by(mtcars, vrb.nm = c("mpg","cyl","disp"),
grp = c("gear","am")) # can handle zero lengths
lengths_by(airquality, c("Ozone","Solar.R","Wind"), grp = "Month",
na.rm = FALSE) # include missing values
lengths_by(airquality, c("Ozone","Solar.R","Wind"), grp = "Month",
na.rm = TRUE) # exclude missing values
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.