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

Description Usage Arguments Value 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
...

Arguments passed on to strsplit.

Value

A character vector.

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/rmisc documentation built on May 17, 2019, 8:54 a.m.