multisplit: Split Data Frame into Multiple Groups

multisplitR Documentation

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 signature 'data.frame,formula'
multisplit(data, grouping, drop = TRUE, sep = ":", ...)

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

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

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

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

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.

Value

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

See Also

split

Examples



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=":")))



growthrates documentation built on Oct. 4, 2022, 1:06 a.m.