textshape (version 1.6.0)

split_index: Split Data Forms at Specified Indices

Description

Split data forms at specified integer indices.

Usage

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, ...)

Arguments

x

A data form (list, vector, data.frame, matrix).

indices

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).

names

Optional vector of names to give to the list elements.

Ignored.

Value

Returns of list of data forms broken at the indices.

See Also

change_index

Examples

Run this code
# 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 DataCamp Workspace