data format error in association rule learning R

2019-09-17 11:28发布

I tried to search other posts in R related to this, but did not find duplicated questions(at least to my efforts). I know I need a priori function in library("a rules") though.

I have a large array file A that each row is a list

user1:  [1,2,3,4]      # [1,2,3,4] is the itemList purchased by this user
user2:  [4]
................

I want to find items that tend to be purchased together. How should I proceed? It seems I need to convert the data to "transaction" format file also.

So I did

temp <- split(A, 1:nrow(A))   # temp is now a list of lists
B <- as(temp, "transactions")

But I got the error "Error in asMethod(object) : can coerce list with atomic components only" Anyone can help?

I googled this example and run the following code without problem

a_list <- list(c("I1","I2","I5"), c("I2","I4"), c("I2","I3"), c("I1","I2","I4"), c("I1","I3"),c("I2","I3"),c("I1","I3"),
c("I1","I2","I3","I5"), c("I1","I2","I3") )

names(a_list) <- paste("T",c(1:9), "00", sep = "")
table5_1 <- as(a_list, "transactions")

Both of temp (in my code) and a_list are of class list, however

     a_list[1]
[[1]]
[1] "I1" "I2" "I5"

     temp[1]
 $`1`
 $`1`$`1`
 [1] 1,2,3,4

How should I correct this? Is this due to the factor my temp file was derived from a data frame?

Thanks

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-09-17 11:53

I had this same error and couldn't figure it out. Finally, I realized that I had null values coming through in the description/item field. I'd check for null/empty strings coming through as that might be the issue (Assuming you have already removed duplicate records for one transaction).

查看更多
登录 后发表回答