我正試圖解決共生矩陣的問題。我有一個交易和項目的數據文件,我想看看項目出現在一起的交易數量矩陣。創建共生矩陣
我是R編程的新手,我很快樂的發現了R的所有快捷方式,而不是創建特定的循環(我曾經使用C年前,現在只堅持使用Excel宏和SPSS )。我在這裏檢查瞭解決方案,但沒有找到可行的解決方案(最接近的解決方案是:Co-occurrence matrix using SAC? - 但是當我使用projected_tm時,它產生了一條錯誤消息,我懷疑cbind在我的情況下不成功。
基本上我有一個包含表如下:
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, etc.
我想創造的東西,如:
A B C D E F
A 0 1 1 0 1 1
B 1 0 3 1 1 0
C 1 3 0 1 0 0
D 1 1 1 0 1 1
E 1 1 0 1 0 0
F 0 1 1 1 0 0
我所做的是什麼(你會在我的新秀 - [R方法很可能笑):
library(igraph)
library(tnet)
trx <- read.table("FileName.txt", header=TRUE)
transID <- t(trx[1])
items <- t(trx[2])
id_item <- cbind(items,transID)
item_item <- projecting_tm(id_item, method="sum")
item_item <- tnet_igraph(item_item,type="weighted one-mode tnet")
item_matrix <-get.adjacency(item_item,attr="weight")
item_matrix
如上所述,cbind可能不成功,所以projection_tm無法給我任何結果。
任何替代方法或更正我的方法?
您的幫助將不勝感激!
相關主題[here](http://stackoverflow.com/questions/14332233/using-graph-adjacency-in-r)。 – hhh
我現在正在處理類似的交易數據,我只想感謝@jacatra(並且hhh發佈的相關帖子也非常有用) – EconomiCurtis
您想要創建的示例中存在一個小錯誤 - B行和F列表示0.它應該說1.困惑了我一段時間。 – vagabond