split_match: Split a Vector By Split Points

Description Usage Arguments Value Author(s) References Examples

View source: R/split_match.R

Description

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

split_match_regex - split_match with regex = TRUE.

Usage

1
2
3
split_match(x, split = "", include = FALSE, regex = FALSE, ...)

split_match_regex(x, split = "", include = FALSE, ...)

Arguments

x

A vector with split points.

split

A vector of places (elements) to split on or a regular expression if regex argument is TRUE.

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 at the end of the output).

regex

logical. If TRUE regular expressions will be enabled for split argument.

...

other arguments passed to grep and grepl.

Value

Returns a list of vectors.

Author(s)

Matthew Flickinger and Tyler Rinker <tyler.rinker@gmail.com>.

References

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
set.seed(15)
x <- sample(c("", LETTERS[1:10]), 25, TRUE, prob=c(.2, rep(.08, 10)))

split_match(x)
split_match(x, "C")
split_match(x, c("", "C"))

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

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

textshape documentation built on May 29, 2021, 1:07 a.m.