Learn R Programming

S4Vectors (version 0.10.2)

split-methods: Divide a vector-like object into groups

Description

split divides the data in a vector-like object x into the groups defined by f.

NOTE: This man page is for the split methods defined in the S4Vectors package. See ?base::split for the default method (defined in the base package).

Usage

"split"(x, f, drop=FALSE)
"split"(x, f, drop=FALSE)
"split"(x, f, drop=FALSE)
"split"(x, f, drop=FALSE, ...)

Arguments

x, f
2 vector-like objects of the same length. f will typically be a factor, but not necessarily.
drop
Logical indicating if levels that do not occur should be dropped (if f is a factor).
...
Arguments passed to base::split (see Details below).

Value

All these methods behave like base::split except that the first 3 methods return a List object instead of an ordinary list.

Details

The first 3 methods just delegate to the IRanges::splitAsList function defined in the IRanges package.

The method for list does:

    split(x, as.vector(f), drop=drop, ...)

See Also

Examples

Run this code
## On an Rle object:
x <- Rle(101:105, 6:2)
split(x, c("B", "B", "A", "B", "A"))

## On a DataFrame object:
groups <- c("group1", "group2")
DF <- DataFrame(
    a=letters[1:10],
    i=101:110,
    group=rep(factor(groups, levels=groups), c(3, 7))
)
split(DF, DF$group)

Run the code above in your browser using DataLab