str_split {stringr} | R Documentation |
Vectorised over string
. pattern
should be
a single pattern, i.e. a character vector of length one.
str_split(string, pattern, n = Inf)
string |
input character vector |
pattern |
pattern to split up by, as defined by a
POSIX regular expression. See the “Extended Regular
Expressions” section of |
n |
maximum number of pieces to return. Default (Inf) uses all possible split positions. |
a list of character vectors.
str_split_fixed
for fixed number of splits
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)