Split data forms at specified integer indices.
split_index(
x,
indices = if (is.atomic(x)) { NULL } else { change_index(x) },
names = NULL,
...
)# S3 method for list
split_index(x, indices, names = NULL, ...)
# S3 method for data.frame
split_index(x, indices, names = NULL, ...)
# S3 method for matrix
split_index(x, indices, names = NULL, ...)
# S3 method for numeric
split_index(x, indices = change_index(x), names = NULL, ...)
# S3 method for factor
split_index(x, indices = change_index(x), names = NULL, ...)
# S3 method for character
split_index(x, indices = change_index(x), names = NULL, ...)
# S3 method for default
split_index(x, indices = change_index(x), names = NULL, ...)
A data form (list
, vector
, data.frame
,
matrix
).
A vector of integer indices to split at. If indices
contains the index 1, it will be silently dropped. The default value when
x
evaluates to TRUE
for is.atomic
is to use
change_index(x)
.
Optional vector of names to give to the list elements.
Ignored.
Returns of list of data forms broken at the indices
.
# NOT RUN {
## character
split_index(LETTERS, c(4, 10, 16))
split_index(LETTERS, c(4, 10, 16), c("dog", "cat", "chicken", "rabbit"))
## numeric
split_index(1:100, c(33, 66))
## factor
(p_chng <- change_index(CO2[["Plant"]]))
split_index(CO2[["Plant"]], p_chng)
#`change_index` was unnecessary as it is the default of atomic vectors
split_index(CO2[["Plant"]])
## list
split_index(as.list(LETTERS), c(4, 10, 16))
## data.frame
(vs_change <- change_index(mtcars[["vs"]]))
split_index(mtcars, vs_change)
## matrix
(mat <- matrix(1:50, nrow=10))
split_index(mat, c(3, 6, 10))
# }
Run the code above in your browser using DataLab