以前曾经问过这个问题,但是在一个旧的帖子中并没有得到解决。人们在这个帖子的底部遇到了这个问题 - Finding 2 & 3 word Phrases Using R TM Package R基本代码和软件包是全新安装的。我无法使用任何二元组或三元组解决方案 - 它们都产生了相同的错误,但我想我会从这里开始。 我将给出一个简单的输出和版本示例。
library("RTextTools")
library(tm)
texts <- c("This is the first document.", "This is the second file.", "This is the third text.")
corpus <- Corpus(VectorSource(texts))
matrix <- create_matrix(texts,ngramLength=3)
Error in simple_triplet_matrix(i = i, j = j, v = as.numeric(v), nrow = length(allTerms), :
'i, j, v' different lengths
In addition: Warning messages:
1: In mclapply(unname(content(x)), termFreq, control) :
all scheduled cores encountered errors in user code
2: In simple_triplet_matrix(i = i, j = j, v = as.numeric(v), nrow = length(allTerms), :
NAs introduced by coercion
print(sessionInfo())
version
_
platform x86_64-apple-darwin13.4.0
arch x86_64
os darwin13.4.0
system x86_64, darwin13.4.0
status
major 3
minor 3.2
year 2016
month 10
day 31
svn rev 71607
language R
version.string R version 3.3.2 (2016-10-31)
nickname Sincere Pumpkin Patch
print(sessionInfo())
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.3
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RTextTools_1.4.2 SparseM_1.74 tm_0.6-2 NLP_0.1-9 Matrix_1.2-7.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 splines_3.3.2 MASS_7.3-45 tau_0.0-18 prodlim_1.5.9
[6] lattice_0.20-34 foreach_1.4.3 caTools_1.17.1 tools_3.3.2 nnet_7.3-12
[11] parallel_3.3.2 grid_3.3.2 ipred_0.9-5 glmnet_2.0-5 e1071_1.6-8
[16] iterators_1.0.8 class_7.3-14 survival_2.39-5 randomForest_4.6-12 lava_1.4.7
[21] bitops_1.0-6 codetools_0.2-15 maxent_1.3.3.1 rpart_4.1-10 slam_0.1-40
[26] tree_1.0-37
答案 0 :(得分:0)
我通过从R版本3.3.2恢复到3.2.2来解决了类似的问题 我的情况略有不同,因为我在tm包中使用DocumentTermMatrix并收到错误:
Error in simple_triplet_matrix(i = i, j = j, v = as.numeric(v), nrow = length(allTerms), :
'i, j' invalid
当我运行R版本3.2.2时,没有发生此错误。升级到3.3.2后,在同一段代码上发生此错误。也许降级可行。对不起,我无法就这个错误发生的原因提供实际答案......