Learn R Programming

qdapTools (version 1.0.2)

split_vector: Split a Vector By Split Points

Description

Splits a vector into a list of vectors based on split points.

Usage

split_vector(x, split = "", include = FALSE)

Arguments

x
A vector with split points.
split
A vector of places (elements) to split on.
include
An integer of 1 (split character(s) are not included in the output), 2 (split character(s) are included at the beginning of the output), or 3 (split character(s) are included

Value

  • Returns a list of vectors.

References

http://stackoverflow.com/a/24319217/1000343

Examples

Run this code
set.seed(15)
x <- sample(c("", LETTERS[1:10]), 25, TRUE, prob=c(.2, rep(.08, 10)))

split_vector(x)
split_vector(x, "C")
split_vector(x, c("", "C"))

split_vector(x, include = 0)
split_vector(x, include = 1)
split_vector(x, include = 2)

set.seed(15)
x <- sample(1:11, 25, TRUE, prob=c(.2, rep(.08, 10)))
split_vector(x, 1)

Run the code above in your browser using DataLab