【发布时间】:2020-12-01 01:05:12
【问题描述】:
所以我有以下df:
df=data.frame(strength=c("10MG;50MG","2MG;5MG","1MG,5MG","100MG;1UG"))
我想标记
library(dplyr)
df %>% mutate(new=as.numeric(unlist(str_extract_all(strength, "[0-9]+"))),check=any(which(new<5)))
【问题讨论】:
-
类似
df$new <- stringr::str_detect(df$strength, "(?<!\\d)[1-4]MG\\b")? -
@WiktorStribiżew,为什么 str_extract_all 在这种情况下不起作用?在我检查之前我需要将其他单位转换为MG
标签: r regex string dplyr stringr