2013-09-21 59 views
1

我的目標是應用關聯規則的文本挖掘。與檢查()函數R錯誤

我有一個字符串此示例:

sample.word = c("abstracting","abstracting workflow","access control","access information","access methods","access patterns","access permissions","access to government information","accountability","acetamides") 

比我做矩陣的所有值0

incidence.matrix_sample <- matrix(0, nrow=5, ncol=length(sample.word)) 

我添加字符串作爲矩陣列

colnames(incidence.matrix_sample) <- sample.word 

現在我把使用匹配函數在文檔中出現的術語列中的1值 (documents.id S [[I]是的文件ID)

for(i in 1:(dim(incidence.matrix_sample)[1])) 
{ 
    incidence.matrix_sample[i, pmatch(documents.ids[[i]], sample.word)] <- 1 
} 

我試着去和第一變換矩陣我作爲itemMatrix,然後作爲交易(如用(my.matrix,「交易」)功能的載體),但是當我嘗試檢查規則,我得到了同樣的錯誤:

incidence.matrix_sample <- as(incidence.matrix_sample, "itemMatrix") 
incidence.matrix_sample <- as(incidence.matrix_sample, "transactions") 
inspect(incidence.matrix_sample) 

結果是:

Errore in UseMethod("inspect", x) : 
    no applicable method for 'inspect' applied to an object of class "c('matrix', 'double', 'numeric')" 

,並使用先驗功能相同的問題incidence.matrix_sample

Errore in UseMethod("inspect", x) : 
    no applicable method for 'inspect' applied to an object of class "c('rules', 'associations')" 

是天,我試圖瞭解問題在哪裏..有人可以幫助我嗎?

+0

首先閱讀http://stackoverflow.com/questions/5963269/how-to-make-a重新生成的例子,稍後發佈。 – zero323

+0

'inspect'是'arules'包提供的S4方法, ,但是您的錯誤消息表明您有一個同名的S3方法, 可能來自另一個包。如果您不加載其他軟件包,或者您明確指定了名稱空間('arules :: inspect'),則問題應該消失。 –

+0

感謝您的答覆,但我嘗試與arules ::檢查,但似乎不起作用 – ntrax

回答

4

這個錯誤的問題是arules和tm庫都有inspect()方法,所以它們的加載順序影響了這個方法的實現方式。

解決此問題的方法是在使用inspect()方法爲使用其他庫創建的對象之前分離庫。例如,獲取關聯矩陣後,我需要分離TM包:

detach(package:tm, unload=TRUE) 

然後加載arules庫,並使用檢查()方法用於arules對象。

我希望這是有用的

+0

我以爲是這樣的,但我忘了我就裝好了tm圖書館:) –

0

您可以使用arules::inspect(incidence.matrix_sample)

::指定哪個庫使用