Given a string, a pattern and natural numbers n
and m
, find the n
th
number that comes before the m
th occurrence of the pattern.
nth_number_before_mth(string, pattern, n, m, decimals = FALSE,
leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)nth_number_before_first(string, pattern, n, decimals = FALSE,
leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)
nth_number_before_last(string, pattern, n, decimals = FALSE,
leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)
first_number_before_mth(string, pattern, m, decimals = FALSE,
leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)
last_number_before_mth(string, pattern, m, decimals = FALSE,
leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)
first_number_before_first(string, pattern, decimals = FALSE,
leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)
first_number_before_last(string, pattern, decimals = FALSE,
leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)
last_number_before_first(string, pattern, decimals = FALSE,
leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)
last_number_before_last(string, pattern, decimals = FALSE,
leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)
A character vector.
A character vector. Pattern(s) specified like the pattern(s)
in the stringr package (e.g. look at stringr::str_locate()
). If
this has length >1 its length must be the same as that of string
.
Natural numbers.
Do you want to include the possibility of decimal numbers
(TRUE
) or not (FALSE
, the default).
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).
Do you want to return the number as a string (TRUE
)
or as numeric (FALSE
, the default)?
A numeric vector.
# NOT RUN {
string <- c("abc1abc2abc3abc4def5abc6abc7abc8abc9",
"abc1def2ghi3abc4def5ghi6abc7def8ghi9")
nth_number_before_mth(string, "def", 1, 1)
nth_number_before_mth(string, "abc", 2, 3)
nth_number_before_first(string, "def", 2)
nth_number_before_last(string, "def", -1)
first_number_before_mth(string, "abc", 2)
last_number_before_mth(string, "def", 1)
first_number_before_first(string, "def")
first_number_before_last(string, "def")
last_number_before_first(string, "def")
last_number_before_last(string, "def")
# }
Run the code above in your browser using DataLab