小编Nel*_*ewR的帖子

从 R 中的字符串中提取拼写出的数字

我正在尝试从字符串中提取拼写出来的数字,并提取数字后面的单词。我设法通过一种费力的方式编写自己的代码来做到这一点,包括要搜索的拼写数字(这里是一个示例stringr::sentences

numbers <- str_c(c(" one ", " two ", " three ", " four ", " five ", " six ", " seven ", " eight "," nine ", " ten "), "([^ ]+)")
number_match <- str_c(numbers, collapse = "|")

reduced <- sentences %>%
   str_detect(number_match)
sent <- sentences[reduced==TRUE]
str_extract(sent, number_match)
Run Code Online (Sandbox Code Playgroud)

这些是提取的字符串:

 [1] " seven books"   " two met"       " two factors"   " three lists"   " seven is"      " two when"      " ten inches."   " one war"      
 [9] " …
Run Code Online (Sandbox Code Playgroud)

numbers text-extraction r

5
推荐指数
0
解决办法
370
查看次数

标签 统计

numbers ×1

r ×1

text-extraction ×1