str_extract_part {forstringr} | R Documentation |
Extract strings before or after a given pattern
Description
Vectorised over string and pattern.
Usage
str_extract_part(string, pattern, before = TRUE)
Arguments
string |
A character vector. |
pattern |
Pattern to look for. |
before |
The position in the string to extract from. If TRUE, the extract will occur before the pattern; if FALSE, it will happen after the pattern. |
Value
A subset of the input vector.
See Also
str_split_extract()
which splits up a string into pieces and extracts the results using a specified index position.
Examples
weekdays <- c(
"Monday_1", "Tuesday_2", "Wednesday_3", "Thursday_4",
"Friday_5", "Saturday_6", "Sunday_7"
)
str_extract_part(weekdays, before = TRUE, pattern = "_")
str_extract_part(c("$159", "$587", "$897"), before = FALSE, pattern = "$")
[Package forstringr version 1.0.0 Index]