Обработка текста: извлечение фиксированного числа чисел из текста - PullRequest
0 голосов
/ 30 апреля 2020

Я пытаюсь сделать следующее:

gg <-c("delete from below 110 11031133 11 11031135 110",
"delete froml #10989431 from adfdaf 10888022 <(>&<)> 10888018",
"this is for the deletion of an incorrect numberss that is no longer used for asd09 and sd040",
"please delete the following mangoes from trey 10246211 1 10821224 1 10821248 1 10821249",
"from 11015647 helppp 1 na from 0050 - zfhhhh 10840637 1")



pattern_to_find <- c('\\d{4,}')

aa <- str_extract_all(gg, pattern_to_find)
aa

с помощью этого кода я могу использовать любой шаблон нумерации c с номером, превышающим фиксированное число. Но если я хочу извлечь 2 номера из набора, то он берет все первые два числа из поля цифры c.

pattern_to_find <- c('\\d{2}').

How can I modify my pattern to work on both ways. 

Regards, 
R

1 Ответ

1 голос
/ 30 апреля 2020

Tidyverse решение:

library(tidyverse)

pattern_to_find <- c('\\d{2,}')

aa <- str_extract_all(gg, pattern_to_find)

База R решение:

base_aa <- regmatches(gg, gregexpr(pattern_to_find, gg))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...