首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于R的文本抽取

基于R的文本抽取
EN

Stack Overflow用户
提问于 2015-08-19 02:39:24
回答 1查看 344关注 0票数 1

我想提取以文本文件中的"i“开头的行。

我试过这个

代码语言:javascript
复制
i <- grep("^i.", text,value = TRUE)

提取包括iii和ii在内的所有谱线。如何解决这个问题?

数据

代码语言:javascript
复制
"i. provides substantial identification and comment upon significant    aspects of texts \\"                                                                                                                                                             
"ii. provides substantial identification and comment upon the creator\\'92s choices \\"                                                                                                                                                               
"iii. sufficiently justifies opinions and ideas with examples and explanations; uses accurate terminology 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-19 02:45:33

我们需要将.转义为字符.。否则,它就意味着任何角色。

代码语言:javascript
复制
grep('^i\\.', text, value=TRUE)
#[1] "i. provides substantial identification and comment upon significant    aspects of texts \\"

数据

代码语言:javascript
复制
text <- c("i. provides substantial identification and comment upon significant    aspects of texts \\", 
"ii. provides substantial identification and comment upon the creator\\'92s choices \\", 
"iii. sufficiently justifies opinions and ideas with examples and explanations; uses accurate terminology ")
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32085670

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档