【发布时间】:2021-02-02 23:59:36
【问题描述】:
我正在尝试基于 R 执行字符串过滤。 我有多个层次结构,我需要将它们组合在一起
我准备了一个例子:
library(stringr)
library(tidyverse)
numbers <- tibble(LEVEL = c('0.1', '0.1.1', '0.1.2', '0.11', '0.12', '0.11.1', '0.12.1', '0.12.2'))
# Return also different values - first shall only contained: 0.1, 0.1.1, 0.1.2
numbers %>%
filter(grepl("^0.1.?", LEVEL))
# Second shall only contained: 0.11, 0.11.1
# Third shall only contained: 0.12, 0.12.1, 0.12.2
我在 grepl 中使用的字符串模式还不够。
【问题讨论】:
-
您能否详细说明您的示例?你想达到什么目标?带有示例和输出。