str_split {stringr}R Documentation

Split up a string into a variable number of pieces.

Description

Split up a string into a variable number of pieces.

Usage

str_split(string, pattern, n=Inf)

Arguments

string input character vector
pattern pattern to split up string by. See regex for description. If NA, returns original string. If "" splits into individual characters.
n maximum number of pieces to return. Default (Inf) uses all possible split positions.

Value

a list of character vectors.

See Also

str_split_fixed for fixed number of splits

Examples

fruits <- c(
"apples and oranges and pears and bananas",
"pineapples and mangos and guavas"
)
str_split(fruits, " and ")

# Specify n to restrict the number of possible matches
str_split(fruits, " and ", n = 3)
str_split(fruits, " and ", n = 2)
# If n greater than number of pieces, no padding occurs
str_split(fruits, " and ", n = 5)

[Package stringr version 0.2 Index]