data format error in association rule learning R

泪湿孤枕 提交于 2020-01-17 06:21:12

问题


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:


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).



来源:https://stackoverflow.com/questions/22884193/data-format-error-in-association-rule-learning-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!