假设我有以下数据:
dat <- read.table(text="TrxID Items Quant
Trx1 A 3
Trx1 B 1
Trx1 C 1
Trx2 E 3
Trx2 B 1
Trx3 B 1
Trx3 C 4
Trx4 D 1
Trx4 E 1
Trx4 A 1
Trx5 F 5
Trx5 B 3
Trx5 C 2
Trx5 D 1", header=T)
term_doc <- xtabs(~ TrxID + Items, data=dat, sparse = TRUE)
co_occur <- crossprod(term_doc, term_doc)
diag(co_occur) <- 0
co_occur
直到昨天,我已经能够运行此代码,并且可以运行。现在我收到以下错误:
> co_occur <- crossprod(term_doc, term_doc)
Error in crossprod(x, y) :
requires numeric/complex matrix/vector arguments
如果我删除sparse = TRUE,则代码可以正常运行(尽管在我的实际数据集上运行缓慢)。为什么我不能再取稀疏矩阵的叉积呢?
答案 0 :(得分:1)
从不同的软件包中有两个具有相同名称的函数,我认为您需要Matrix::crossprod
而不是base::crossprod
。