[英]Split by paragraph in R
我正在尝试在 R 中按段落拆分文档
test.text <- c("First paragraph. Second sentence of 1st paragraph.
Second paragraph.")
# When we run the below, we see separation of \n\n between the 2nd and 3rd sentences
test.text
# This outputs the desired 2 blank lines in the console
writeLines("\n\n")
a <- strsplit(test.text, "\\n\\n")
它没有正确拆分。
strsplit
的输出是一个list
。 此外, \\n\\n
之后还有空格。 因此,我们需要注意这一点,并使用[[
或通过unlist
将其转换为vector
a <- strsplit(test.text, "\n+\\s+")[[1]]
a
#[1] "First paragraph. Second sentence of 1st paragraph." "Second paragraph."
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.