| split-methods {S4Vectors} | R Documentation |
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).
## S4 method for signature 'Vector,ANY' split(x, f, drop=FALSE) ## S4 method for signature 'ANY,Vector' split(x, f, drop=FALSE) ## S4 method for signature 'Vector,Vector' split(x, f, drop=FALSE) ## S4 method for signature 'list,Vector' split(x, f, drop=FALSE, ...)
x, f |
2 vector-like objects of the same length. |
drop |
Logical indicating if levels that do not occur should be dropped (if
|
... |
Arguments passed to |
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, ...)
All these methods behave like base::split except that the
first 3 methods return a List object instead of an ordinary list.
The split function in the base package.
The splitAsList function in the IRanges
package.
## 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)