嗨,我有一个非常大的txt文件(字符),我想提取10%的条目,并将它们保存到另一个txt文件中。
con1 <- file("ABC.txt", "rb") # 2,36 mio DS
dfc1<-readLines(con1, ??? ,skipNul = TRUE)#而不是?我想要<10%的data>。
所以如果我的ABC.txt
英国广播公司( BBC )是英国广播公司( BBC )的主要商业部门和全资子公司。它的存在是为了支持英国广播公司的公共服务使命,并代表英国广播公司实现利润最大化……
我的新文件应该只包含10% (随机)的单词,如:
“全球商业代表.”
在R ?中有这样的方法吗?
谢谢
发布于 2018-03-03 17:20:10
如果在文本文件中读取,则可以使用stringr包获得10%的随机单词示例,使用以下代码:
text<- c("BBC Worldwide is a principle commercial arm and a wholly owned subsidiary of the British Broadcasting Corporation (BBC). The business exists to support the BBC public service mission and to maximise profits on its behalf...")
set.seed(9999)
library(stringr)
selection<-sample.int(str_count(text," ")+1, round(0.1*str_count(text," ")+1))
subset<-word(text, selection)https://stackoverflow.com/questions/49086487
复制相似问题