Description Usage Arguments Details Value Note Examples
Split a character vector, reorder the substrings, and paste back together.
1 2 3 4 5 6 7 | order_substr(
x,
split = "\\s*,\\s*|\\s*/\\s*|\\s*-\\s*|\\s+",
perl = TRUE,
collapse = " ",
reverse = FALSE
)
|
x |
a character vector. |
split |
a regular expressin by which to split. See Details. |
perl |
logical, whether to interpret |
collapse |
a character string with which to collapse the re-ordered sub-strings. |
reverse |
logical, whether to reverse the ordering. |
By default, order_substr() splits each string of a character vector at any commas,
forward slashes, hyphens, and whitespace, regardless of whether these characters
are surrounded by whitespace.
Alternative regular expressions for splitting can be used via split.
Other strings may be used to separate the alphabetized output via collapse.
A character vector with substrings ordered alphabetically and re-collapsed.
Cleaning with order_substr() works poorly when substrings are inconsistently separated
by the split pattern. For example, the vector of tuna species below hyphenates yellow-fin
but leaves bluefin as a single word. Therefore, with the default split patterns,
order_substr() splits yellow-fin prior to alphabetization.
1 2 3 4 5 | tuna <- c("tuna,skipjack", "tuna , bluefin", "yellow-fin - tuna", "tuna, albacore")
order_substr(tuna)
colors <- c("green/red", "yellow / blue", "orange purple")
order_substr(colors, collapse = "-", reverse = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.