loc_split | R Documentation |
Split data forms at specified integer locations.
loc_split(x, locs, names = NULL, ...)
## S3 method for class 'list'
loc_split(x, locs, names = NULL, ...)
## S3 method for class 'data.frame'
loc_split(x, locs, names = NULL, ...)
## S3 method for class 'matrix'
loc_split(x, locs, names = NULL, ...)
## S3 method for class 'numeric'
loc_split(x, locs, names = NULL, ...)
## S3 method for class 'factor'
loc_split(x, locs, names = NULL, ...)
## S3 method for class 'character'
loc_split(x, locs, names = NULL, ...)
## Default S3 method:
loc_split(x, locs, names = NULL, ...)
x |
A data form ( |
locs |
A vector of integer locations to split at. If |
names |
Optional vector of names to give to the list elements. |
... |
Ignored. |
Returns of list of data forms broken at the locs
.
Two dimensional object will retain dimension (i.e., drop = FALSE
is used).
run_split
,
split_vector
https://github.com/trinker/loc_split_example for practical usage.
## character
loc_split(LETTERS, c(4, 10, 16))
loc_split(LETTERS, c(4, 10, 16), c("dog", "cat", "chicken", "rabbit"))
## numeric
loc_split(1:100, c(33, 66))
## factor
(p_chng <- head(1 + cumsum(rle(as.character(CO2[["Plant"]]))[[1]]), -1))
loc_split(CO2[["Plant"]], p_chng)
## list
loc_split(as.list(LETTERS), c(4, 10, 16))
## data.frame
(vs_change <- head(1 + cumsum(rle(as.character(mtcars[["vs"]]))[[1]]), -1))
loc_split(mtcars, vs_change)
## matrix
(mat <- matrix(1:50, nrow=10))
loc_split(mat, c(3, 6, 10))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.