split_by {expss} | R Documentation |
Splits data.frame into list of data.frames that can be analyzed separately
Description
Splits data.frame into list of data.frames that can be analyzed separately.
These data.frames are sets of cases that have the same values for the
specified split variables. Any missing values in split variables are dropped
together with the corresponding values of data
. split_off
works
with lists of data.frames or objects that can be coerced to data.frame and
assumed to have compatible structure. Resulting rows will be sorted in order
of the split variables.
Usage
split_by(data, ..., drop = TRUE)
split_off(data, groups = NULL, rownames = NULL)
Arguments
data |
data.frame for |
... |
unquoted variables names (see keep) by which |
drop |
should we drop combination of levels with zero observation? TRUE by default. |
groups |
character If it is not |
rownames |
character If it is not |
Value
split_by
returns list of data.frames/split_off
returns data.frame
See Also
Examples
# usage of 'groups', 'rownames'
data(mtcars)
# add labels to dataset
mtcars %>%
apply_labels(mpg = "Miles/(US) gallon",
disp = "Displacement (cu.in.)",
wt = "Weight",
hp = "Gross horsepower",
vs = "Engine",
vs = num_lab("
0 V-engine
1 Straight engine
"),
am = "Transmission",
am = num_lab("
0 Automatic
1 Manual
")
) %>%
split_by(am, vs) %>%
to_list({
res = lm(mpg ~ hp + disp + wt, data = .x)
cbind(Coef. = coef(res), confint(res))
}) %>%
split_off(groups = TRUE, rownames = "variable")