读取文本文件,按分隔符创建新行

时间:2015-11-22 05:38:31

标签: r read.table

我正在尝试将文本文件作为数据框导入为单列和多行。我想为每个句子创建一个新行,我想为每个单词重复这个过程。

喜欢这个。

  

先生。特朗普在共和党总统大选中一直领导大多数国家民意调查,但他面临着一个可能发生变化的局面。在不到三个月的时间里,在爱荷华州的预选会议上,上周在巴黎发生的恐怖袭击事件后,人们的注意力转向了国家安全。虽然共和党选民到目前为止一直支持像特朗普和本卡森这样的政治局外人,但对恐怖主义和难民从叙利亚到美国的关注可能会改变事态。

应该被理解为

  

V1

     

[1]先生

     

[2]特朗普在共和党总统大选中一直领导大多数国家民意调查,但他面临着可能发生变化的景观

     

[3]爱荷华州预选会议不到三个月,上周在巴黎发生恐怖袭击事件后,人们的注意力转移到了国家安全上。

     

[4]虽然到目前为止共和党选民一直支持像

这样的政治局外人      [5]特朗普和本卡森,对恐怖主义和难民从叙利亚到美国的关注可能会改变事态

感谢。

1 个答案:

答案 0 :(得分:0)

我们可以使用strsplit

strsplit(txt, '[.]\\s*')[[1]]

数据

txt <- "Mr. Trump has been leading most national polls in the Republican presidential contest, but he is facing a potentially changed landscape. With the Iowa caucuses less than three months away, attention has shifted to national security in the wake of the terrorist attacks in Paris last week. While the Republican electorate so far has favored political outsiders like Mr. Trump and Ben Carson, the concerns over terrorism and the arrival of refugees from Syria into the United States could change things."
相关问题