Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

splitter_d

Split a data frame by variables.


Description

Split a data frame into pieces based on variable contained in that data frame

Usage

splitter_d(data, .variables = NULL, drop = TRUE)

Arguments

data

data frame

.variables

a quoted list of variables

drop

drop unnused factor levels?

Details

This is the workhorse of the d*ply functions. Based on the variables you supply, it breaks up a single data frame into a list of data frames, each containing a single combination from the levels of the specified variables.

This is basically a thin wrapper around split which evaluates the variables in the context of the data, and includes enough information to reconstruct the labelling of the data frame after other operations.

Value

a list of data.frames, with attributes that record split details

See Also

. for quoting variables, split

Other splitter functions: splitter_a()

Examples

plyr:::splitter_d(mtcars, .(cyl))
plyr:::splitter_d(mtcars, .(vs, am))
plyr:::splitter_d(mtcars, .(am, vs))

mtcars$cyl2 <- factor(mtcars$cyl, levels = c(2, 4, 6, 8, 10))
plyr:::splitter_d(mtcars, .(cyl2), drop = TRUE)
plyr:::splitter_d(mtcars, .(cyl2), drop = FALSE)

mtcars$cyl3 <- ifelse(mtcars$vs == 1, NA, mtcars$cyl)
plyr:::splitter_d(mtcars, .(cyl3))
plyr:::splitter_d(mtcars, .(cyl3, vs))
plyr:::splitter_d(mtcars, .(cyl3, vs), drop = FALSE)

plyr

Tools for Splitting, Applying and Combining Data

v1.8.6
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.