grep 在 R 中的多个模式给出无法解释的结果
grep on multiple patterns in R giving unexplained results
ExecKeywords <- c('cio','cto','cco','coo','ciso','cso','cdo','cdio',
'Chief Information','CIO','Chief Technology Officer','Chief Compliance Officer','Chief Security')
Titles <- c('Director - Customer Success','CIO','Director Cloud Operations',
'Director of Information Technology and Chief Information Security Officer',
'Director, Information Services','Director, Global Information Technology',
'Chief Technology Officer','Sr. Director','COO / CTO Advice Company',
'Director of Information Technology','Director of Technology',
'Vice President, Platform Operations and Information Technology',
'Accounting Manager','VP, Strategy and Programs','IT Director','CTO',
'Director of Network Services','Director','Director, Application Engineering',
'Deputy Director of Technology')
grep(paste(ExecKeywords, collapse = "|"), Titles, value = T)
我正在尝试识别与 ExecKeywords 中找到的多种模式之一相匹配的标题。在 ExecKeywords 的每个元素之后、管道之前和管道之后(折叠)放置一个 space 似乎都做了一些不同的事情,但不是我想要的。所有帖子都引用了粘贴和折叠方法,但这似乎对我不起作用……我是不是遗漏了什么? ignore.case 似乎也没有按预期工作
应该期待这样的 return
'CIO','Director of Information Technology and Chief Information Security Officer','Chief Technology Officer','COO / CTO Advice Company','CTO'
一个选项是也有一个单词边界 paste
d 以避免匹配单词中的子字符串
grep(paste0("\b(", paste(ExecKeywords, collapse = "|"), ")\b"),
Titles, value = TRUE, ignore.case = TRUE)
#[1] "CIO"
#[2] "Director of Information Technology and Chief Information Security Officer"
#[3] "Chief Technology Officer"
#[4] "COO / CTO Advice Company"
#[5] "CTO"
ExecKeywords <- c('cio','cto','cco','coo','ciso','cso','cdo','cdio',
'Chief Information','CIO','Chief Technology Officer','Chief Compliance Officer','Chief Security')
Titles <- c('Director - Customer Success','CIO','Director Cloud Operations',
'Director of Information Technology and Chief Information Security Officer',
'Director, Information Services','Director, Global Information Technology',
'Chief Technology Officer','Sr. Director','COO / CTO Advice Company',
'Director of Information Technology','Director of Technology',
'Vice President, Platform Operations and Information Technology',
'Accounting Manager','VP, Strategy and Programs','IT Director','CTO',
'Director of Network Services','Director','Director, Application Engineering',
'Deputy Director of Technology')
grep(paste(ExecKeywords, collapse = "|"), Titles, value = T)
我正在尝试识别与 ExecKeywords 中找到的多种模式之一相匹配的标题。在 ExecKeywords 的每个元素之后、管道之前和管道之后(折叠)放置一个 space 似乎都做了一些不同的事情,但不是我想要的。所有帖子都引用了粘贴和折叠方法,但这似乎对我不起作用……我是不是遗漏了什么? ignore.case 似乎也没有按预期工作
应该期待这样的 return
'CIO','Director of Information Technology and Chief Information Security Officer','Chief Technology Officer','COO / CTO Advice Company','CTO'
一个选项是也有一个单词边界 paste
d 以避免匹配单词中的子字符串
grep(paste0("\b(", paste(ExecKeywords, collapse = "|"), ")\b"),
Titles, value = TRUE, ignore.case = TRUE)
#[1] "CIO"
#[2] "Director of Information Technology and Chief Information Security Officer"
#[3] "Chief Technology Officer"
#[4] "COO / CTO Advice Company"
#[5] "CTO"