Break a string wherever you go from a numeric character to a non-numeric or vice-versa. Keep the whole string, just split it up. Vectorised over string.
string
str_split_by_numbers(string, decimals = FALSE, leading_decimals = FALSE, negs = FALSE, sci = FALSE, commas = FALSE)
A string.
Do you want to include the possibility of decimal numbers (TRUE) or not (FALSE, the default).
TRUE
FALSE
Do you want to allow a leading decimal point to be the start of a number?
Do you want to allow negative numbers? Note that double negatives are not handled here (see the examples).
Make the search aware of scientific notation e.g. 2e3 is the same as 2000.
Allow comma separators in numbers (i.e. interpret 1,100 as a single number (one thousand one hundred) rather than two numbers (one and one hundred)).
A list of character vectors.
Other splitters: str_split_camel_case
str_split_camel_case
# NOT RUN { str_split_by_numbers(c("abc123def456.789gh", "a1b2c344")) str_split_by_numbers("abc123def456.789gh", decimals = TRUE) str_split_by_numbers(c("22", "1.2.3"), decimals = TRUE) # }
Run the code above in your browser using DataLab