Description Usage Arguments Value See Also Examples
Vectorised over string
and pattern
.
1 2 3  str_split(string, pattern, n = Inf, simplify = FALSE)
str_split_fixed(string, pattern, n)

string 
Input vector. Either a character vector, or something coercible to one. 
pattern 
Pattern to look for. The default interpretation is a regular expression, as described
in stringi::stringisearchregex. Control options with
Match a fixed string (i.e. by comparing only bytes), using
Match character, word, line and sentence boundaries with

n 
number of pieces to return. Default (Inf) uses all possible split positions. For 
simplify 
If 
For str_split_fixed
, a character matrix with n
columns.
For str_split
, a list of character vectors.
stri_split()
for the underlying implementation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17  fruits < c(
"apples and oranges and pears and bananas",
"pineapples and mangos and guavas"
)
str_split(fruits, " and ")
str_split(fruits, " and ", simplify = TRUE)
# 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)
# Use fixed to return a character matrix
str_split_fixed(fruits, " and ", 3)
str_split_fixed(fruits, " and ", 4)

[[1]]
[1] "apples" "oranges" "pears" "bananas"
[[2]]
[1] "pineapples" "mangos" "guavas"
[,1] [,2] [,3] [,4]
[1,] "apples" "oranges" "pears" "bananas"
[2,] "pineapples" "mangos" "guavas" ""
[[1]]
[1] "apples" "oranges" "pears and bananas"
[[2]]
[1] "pineapples" "mangos" "guavas"
[[1]]
[1] "apples" "oranges and pears and bananas"
[[2]]
[1] "pineapples" "mangos and guavas"
[[1]]
[1] "apples" "oranges" "pears" "bananas"
[[2]]
[1] "pineapples" "mangos" "guavas"
[,1] [,2] [,3]
[1,] "apples" "oranges" "pears and bananas"
[2,] "pineapples" "mangos" "guavas"
[,1] [,2] [,3] [,4]
[1,] "apples" "oranges" "pears" "bananas"
[2,] "pineapples" "mangos" "guavas" ""
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.