R 重新格式化文本文件间距(从导入的文本中剥离选项卡)
我有一个文本文件,其中包含以下格式的句子:R 重新格式化文本文件间距(从导入的文本中剥离选项卡),r,R,我有一个文本文件,其中包含以下格式的句子: Blah blah blah blah blah blah. Another random sentence that sentence continued. 我想知道是否有办法重新格式化文本,这样就没有标签了,所以基本上: Blah blah blah blah blah blah. Another random sentence that sentence continued. 或: 这里有一些选择。如果您在问题中创建了文本文件或dput()阅
Blah blah blah
blah blah blah.
Another random sentence
that sentence continued.
我想知道是否有办法重新格式化文本,这样就没有标签了,所以基本上:
Blah blah blah blah blah blah.
Another random sentence that sentence continued.
或:
这里有一些选择。如果您在问题中创建了文本文件或
dput()
阅读文本文件后得到的内容,则会更清楚您面临的问题
fileConn <- file("delete_me.txt")
writeLines(c("Blah blah blah",
"blah blah blah.",
"Another random sentence",
"that sentence continued."), fileConn)
close(fileConn)
text <- read.delim("delete_me.txt",
header=F)
text
如果你有问题,请告诉我
text="Blah blah blah
blah blah blah.
Another random sentence
that sentence continued."
gsub("\n", " ", text)
V1
1 Blah blah blah
2 blah blah blah.
3 Another random sentence
4 that sentence continued.
paste(text$V1, collapse = " ")
[1] "Blah blah blah blah blah blah. Another random sentence that sentence continued."
text="Blah blah blah
blah blah blah.
Another random sentence
that sentence continued."
gsub("\n", " ", text)
"Blah blah blah blah blah blah. Another random sentence that sentence continued."
strsplit(gsub("\n", "", text), ".",fixed=T)
"Blah blah blahblah blah blah"
"Another random sentencethat sentence continued"