У меня есть набор случайного текста в столбце, например:
dplyr::tibble(text = c("I have a (brown) clock", "surrounded by (red) walls", "inside of a (blue) building with (dirty) windows",
"where (magical) things (unexpectedly) occur (spontaneously)"))
# A tibble: 4 x 1
text
<chr>
1 I have a (brown) clock
2 surrounded by (red) walls
3 inside of a (blue) building with (dirty) windows
4 where (magical) things (unexpectedly) occur (spontaneously)
Я бы хотел извлечь последнюю встречающуюся строку в скобках в другой столбец, чтобы она выглядела так:
dplyr::tibble(text = c("I have a (brown) clock", "surrounded by (red) walls", "inside of a (blue) building with (dirty) windows",
"where (magical) things (unexpectedly) occur (spontaneously)"),
extract = c("brown", "red", "dirty", "spontaneously"))
# A tibble: 4 x 2
text extract
<chr> <chr>
1 I have a (brown) clock brown
2 surrounded by (red) walls red
3 inside of a (blue) building with (dirty) windows dirty
4 where (magical) things (unexpectedly) occur (spontaneously) spontaneously