Split a dataframe according to the levels of variables in the dataframe. The variables to split by can be given as a formula or as a character vector.
split_by(data, formula, drop =TRUE)splitBy(formula, data = parent.frame(), drop =TRUE)## S3 method for class 'splitByData'head(x, n =6L,...)## S3 method for class 'splitByData'tail(x, n =6L,...)
Arguments
data: A data frame
formula: Variables to split data frame by, as as.quoted
variables, a formula or character vector.
drop: Logical indicating if levels that do not occur should be dropped. Deprecated; levels that do not occur are ignored.
x: An object.
n: A single integer. If positive or zero, size for the resulting object: number of elements for a vector (including lists), rows for a matrix or data frame or lines for a function. If negative, all but the "n" last/first number of elements of "x".
...: Arguments to be passed to or from other methods.
Returns
A list of dataframes.
Examples
data(dietox, package="doBy")splitBy(formula =~Evit + Cu, data = dietox)splitBy(formula = c("Evit","Cu"), data = dietox)splitBy(~Treatment + Type, data=CO2)splitBy(c("Treatment","Type"), data=CO2)x <- splitBy(~Treatment, data=CO2)head(x)tail(x)