题
简单问题......例如:
data("crude")
.
是一种带有20个文本文档的语料库,我如何获得类似的东西:
1 4
2 6
3 5
4 3
etc...
.
第二列是语料库“粗糙”中每个文档的行数?甚至是行号码的向量将工作。
nrow / nrow似乎没有工作。
谢谢!
解决方案
嗨,您可以使用
计算线路馈送(LF)library(stringr)
str_count(string = crude[[1]], pattern = "\\n")
# [1] 11
.
crude[[1]]
在我的计算机上有12行,所以对于所有的语料库,您可以执行以下操作:
sapply(crude, FUN = function(x) str_count(string = x, pattern = "\\n") + 1)
. 其他提示
除线外,如果您的实际数据是data.frame,那么您可以找到项目数。检查这个
data = data.frame(x=1:5,y=1:5,z=1:5)
corp = Corpus(DataframeSource(data))
corp[[1]]
#Output
1
1
1
lapply(corp,length)
#Output
$`1`
[1] 3
$`2`
[1] 3
$`3`
[1] 3
$`4`
[1] 3
$`5`
[1] 3
. 不隶属于 StackOverflow