Learn R Programming

growthrates (version 0.8.4)

multisplit: Split Data Frame into Multiple Groups

Description

A data frame is split into a list of data subsets defined by multiple groups.

Usage

multisplit(data, grouping, drop = TRUE, sep = ":", ...)

# S4 method for data.frame,formula multisplit(data, grouping, drop = TRUE, sep = ":", ...)

# S4 method for data.frame,character multisplit(data, grouping, drop = TRUE, sep = ":", ...)

# S4 method for data.frame,factor multisplit(data, grouping, drop = TRUE, sep = ":", ...)

# S4 method for data.frame,list multisplit(data, grouping, drop = TRUE, sep = ":", ...)

# S4 method for ANY,ANY multisplit(data, grouping, drop = TRUE, sep = ":", ...)

Value

list containing data frames of the data subsets as its elements. The components of the list are named by their grouping levels.

Arguments

data

data frame, matrix or vector containing several subsets of data

grouping

either a character vector containing the names of the grouping variables or a model formula specifying dependent, independent and grouping variables in the form: dependent ~ independent | group1 + group2 + .... It may also be a factor or list of factors as in split.

drop

if drop is TRUE, unused factor levels are dropped from the result. The default is to drop all factor levels.

sep

string to construct the new level labels by joining the constituent ones.

...

other parameters passed to split, see details.

Details

This function is wrapper around split with different defaults, slightly different behavior, and methods for additional argument classes. multisplit returns always a data frame.

See Also

Examples

Run this code


data(bactgrowth)

## simple method
spl <- multisplit(bactgrowth, c("strain", "conc", "replicate"))

## preferred method
spl <- multisplit(bactgrowth, value ~ time | strain + conc + replicate)

## show what is in one data set
spl[[1]]
summary(spl[[1]])

## use factor combination
spl[["D:0:1"]]
summary(spl[["D:0:1"]])


lapply(spl, FUN=function(x)
 plot(x$time, x$value,
      main=paste(x[1, "strain"], x[1, "conc"], x[1, "replicate"], sep=":")))


Run the code above in your browser using DataLab