【发布时间】:2020-04-28 18:14:56
【问题描述】:
我在这样的列中有一组随机文本:
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
【问题讨论】: