2013-04-10 88 views
0

我想用arules包練關聯規則挖掘與R. 的數據是無法轉換數據幀的交易對象

datt <- structure(list(Item1 = c(0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 
0L), Item2 = c(0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 0L), Item3 = c(0L, 
1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 0L), Item4 = c(0L, 0L, 0L, 1L, 
0L, 0L, 0L, 0L, 0L, 0L), Item5 = c(1L, 0L, 0L, 1L, 0L, 0L, 0L, 
0L, 0L, 1L), Item6 = c(0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L 
), Item7 = c(0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L), Item8 = c(0L, 
1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L), Item9 = c(0L, 1L, 1L, 1L, 
0L, 0L, 0L, 0L, 1L, 0L), Item10 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L)), .Names = c("Item1", "Item2", "Item3", "Item4", 
"Item5", "Item6", "Item7", "Item8", "Item9", "Item10"), row.names = c(2L, 
3L, 4L, 5L, 6L, 8L, 9L, 10L, 11L, 12L), class = c("cast_df", 
"data.frame")) 

這樣做

table5 <- as(datt, "transactions") 

這個錯誤變成了:

Error in as(datt, "transactions") : 
    no method or default for coercing 「cast_df」 to 「transactions」 

我能做些什麼來將我的對象轉換爲「交易」反對呢?

回答

1

試試這個:

as(as.matrix(datt), "transactions") 
transactions in sparse format with 
10 transactions (rows) and 
10 items (columns) 

的錯誤是明顯的位置:

no method or default for coercing 「cast_df」 to 「transactions」 

class(datt)cast_df和這種類型的沒有脅迫的方法(as)。

請注意,當您使用arules程序包時,通常不需要手動強制執行強制轉換,該函數會嘗試在內部執行正確的強制轉換。例如:

dissimilarity(x=as.matrix(datt),method='cosine') ## works 
dissimilarity(x=datt,method='cosine')   ## you get the same coercion error 
+0

THX在我的電腦您的幫助。但是,有一個與你的way.The錯誤錯誤如下:ERROE:如(as.matrix( datt),「transactions」): 沒有方法或強制將「cast_matrix」強制爲「transactions」 – causjc 2013-04-10 13:28:19

0

對於我這種工作

install.packages("arules")