Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 重新格式化文本文件间距(从导入的文本中剥离选项卡)_R - Fatal编程技术网

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"