strsplitN: Split up a string in pieces and return the nth piece.

Description Usage Arguments Value See Also Examples

Description

Split up a string in pieces and return the nth piece.

Usage

1
strsplitN(x, split, n, from = "start", collapse = split, ...)

Arguments

x

character vector to be split.

split

regular expression used for splitting.

n

Vector of elements to be returned.

from

One of ‘start’ or ‘end’. From which direction do we count the pieces.

collapse

an optional character string to separate the results.

...

Arguments passed on to strsplit.

Value

A character vector.

See Also

Other string-utils: blanks, dup, pad, replace_ext, split_path, strip_ext, trim, wrap

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
str <- c("Lorem, ipsum, dolor", "consectetur, adipisicing, elit")
strsplitN(str, ", ", 1)
## [1] "Lorem"
## [2] "consectetur"
strsplitN(str, ", ", 1, from="end")
## [1] "dolor"
## [2] "elit"
strsplitN(str, ", ", 1:2)
## [1] "Lorem, ipsum"
## [2] "consectetur, adipisicing"
strsplitN(str, ", ", 1:2, collapse = "--")
## [1] "Lorem--ipsum"
## [2] "consectetur--adipisicing"

gschofl/gsmisc documentation built on May 17, 2019, 8:52 a.m.