【问题标题】:reducing whitespace to 1 space between words将空格减少到单词之间的 1 个空格
【发布时间】:2016-08-04 14:35:15
【问题描述】:

我有一个已删除符号的 Facebook 帖子列表。现在我在文本之间留下了空白 - 2个或更多空格,我想浓缩。如何删除多余的空格,使单词之间只有一个空格?此外,如何删除文本中所有独立的大写字母?

> head(posts)
[1] "Syntel Recruitment Drive in this week for FRESHERS   New Registration Link 2016 for 2013 2014 2015 Passout Graduates Qualification   Any Graduate B E B Tech MCA M E M Tech Syntel Registration Link"            
[2] "Dont Miss This Opportunity to be get placed in one of the best MNC companies in the world   eBay freshers this week of January 2016  Qualification   Any Graduate Can Apply   eBay Registration Link"            
[3] "Recent Pass Outs with 55  or More are eligible to Apply in  Wipro   Go to the Updated Link for  LastDay Reference Drive  Jan 2016  Apply Link for  Fresher  Referral  Apply Link"                                
[4] "Robert Bosch Recruitment Drive in this week for FRESHERS   New Registration Link 2016 for 2013 2014 2015 Passout Graduates Qualification   Any Graduate B E B Tech MCA M E M Tech Robert Bosch Registration Link"
[5] "Mega  JOB  OPENINGS  OF  THE  YEAR  Mphasis Recruitment for FRESHERS January 2016 Qualification   BE  B Tech  B Sc  BCA  Any Graduates  MCA  MBA  ME  M Tech  Post Graduates  Mphasis Registration Link"         
[6] "TRIGENT Recruitment Drive in this week for FRESHERS   New Registration Link 2016 for 2013 2014 2015 Passout Graduates Qualification   Any Graduate B E B Tech MCA M E M Tech Trigent Registration Link"  


> dput(head(posts))
c("Syntel Recruitment Drive in this week for FRESHERS   New Registration Link 2016 for 2013 2014 2015 Passout Graduates Qualification   Any Graduate B E B Tech MCA M E M Tech Syntel Registration Link", 
"Dont Miss This Opportunity to be get placed in one of the best MNC companies in the world   eBay freshers this week of January 2016  Qualification   Any Graduate Can Apply   eBay Registration Link", 
"Recent Pass Outs with 55  or More are eligible to Apply in  Wipro   Go to the Updated Link for  LastDay Reference Drive  Jan 2016  Apply Link for  Fresher  Referral  Apply Link", 
"Robert Bosch Recruitment Drive in this week for FRESHERS   New Registration Link 2016 for 2013 2014 2015 Passout Graduates Qualification   Any Graduate B E B Tech MCA M E M Tech Robert Bosch Registration Link", 
"Mega  JOB  OPENINGS  OF  THE  YEAR  Mphasis Recruitment for FRESHERS January 2016 Qualification   BE  B Tech  B Sc  BCA  Any Graduates  MCA  MBA  ME  M Tech  Post Graduates  Mphasis Registration Link", 
"TRIGENT Recruitment Drive in this week for FRESHERS   New Registration Link 2016 for 2013 2014 2015 Passout Graduates Qualification   Any Graduate B E B Tech MCA M E M Tech Trigent Registration Link"
)

【问题讨论】:

    标签: r text text-mining gsub


    【解决方案1】:

    使用gsub,你可以试试

    posts <- gsub(" +", " ", posts)
    

    这将用一个空格替换每组相邻的空格。

    【讨论】:

      猜你喜欢
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      相关资源
      最近更新 更多