简体   繁体   中英

Transform a dataset to summarize table in R

I am learning data mining about market basket analysis and would like to transform the rawdata to a summarize table for further calculation of support and confidence.

Below is an example that about 4 transactions that indicate the customer has purchased corresponding item.

Example is like following:

在此处输入图片说明

Afterwards would like to have all possible item sets. For above example, total possibility is 2 4 item sets.

It sounds like you're looking for the crossprod function:

M <- data.frame(ID = 1:4, A = c(1, 0, 1, 0), 
                B = c(1, 1, 0, 0), C = c(0, 1, 1, 0), 
                D = c(0, 0, 1, 1))
crossprod(as.matrix(M[-1]))
#   A B C D
# A 2 1 1 1
# B 1 2 1 0
# C 1 1 2 1
# D 1 0 1 2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM