R: Find the nth number after the mth occurrence of a pattern.

nth_number_after_mth {filesstrings} | R Documentation

## Find the nth number after the mth occurrence of a pattern.

### Description

Given a string, a pattern and natural numbers `n` and `m`, find the `n`th number after the `m`th occurrence of the pattern.

### Usage

    nth_number_after_mth(string, pattern, n, m, decimals = FALSE,
      leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)

    nth_number_after_first(string, pattern, n, decimals = FALSE,
      leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)

    nth_number_after_last(string, pattern, n, decimals = FALSE,
      leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)

    first_number_after_mth(string, pattern, m, decimals = FALSE,
      leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)

    last_number_after_mth(string, pattern, m, decimals = FALSE,
      leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)

    first_number_after_first(string, pattern, decimals = FALSE,
      leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)

    first_number_after_last(string, pattern, decimals = FALSE,
      leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)

    last_number_after_first(string, pattern, decimals = FALSE,
      leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)

    last_number_after_last(string, pattern, decimals = FALSE,
      leading_decimals = FALSE, negs = FALSE, leave_as_string = FALSE)

### Arguments

`string` | A character vector.
`pattern` | 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`.
`n, m` | Natural numbers.
`decimals` | Do you want to include the possibility of decimal numbers (`TRUE`) or not (`FALSE`, the default).
`leading_decimals` | Do you want to allow a leading decimal point to be the start of a number?
`negs` | Do you want to allow negative numbers? Note that double negatives are not handled here (see the examples).
`leave_as_string` | Do you want to return the number as a string (`TRUE`) or as numeric (`FALSE`, the default)?

### Value

A numeric vector.

### Examples

    string <- c("abc1abc2abc3abc4abc5abc6abc7abc8abc9",
                "abc1def2ghi3abc4def5ghi6abc7def8ghi9")
    nth_number_after_mth(string, "abc", 1, 3)
    nth_number_after_mth(string, "abc", 2, 3)
    nth_number_after_first(string, "abc", 2)
    nth_number_after_last(string, "abc", -1)
    first_number_after_mth(string, "abc", 2)
    last_number_after_mth(string, "abc", 1)
    first_number_after_first(string, "abc")
    first_number_after_last(string, "abc")
    last_number_after_first(string, "abc")
    last_number_after_last(string, "abc")

[Package filesstrings version 2.5.0 Index]