Description Usage Arguments Examples
View source: R/string_manipulation.R
Extract portions of a string as defined by a separator such as a comma or whitespace. For example, in a vector strings of first and last name, such as "Bob Smith", the first name can be extracted as item number one and last name as item number two.
1 | get_text_item(x, item = 2, sep = " ")
|
x |
A vector of character strings |
item |
The relative position of the item to extract |
sep |
The separator used to split the string |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | # Define a vector of names that need to be broken out into columns
fish_names = tibble::tibble(names = c("Coho Salmon, Silvers",
"Chinook Salmon, Kings"))
# Pull out the common name
fish_names$common_name = get_text_item(fish_names$names,
item = 1, sep = " ")
# Pull out the alternate common name
fish_names$alternate_name = get_text_item(fish_names$names,
item = 2, sep = ",")
# Trim whitespace from alternate_name
fish_names$alternate_name = trimws(fish_names$alternate_name, "b")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.