2

当我这样做的时候进展顺利

library(arules) 
mydata=read.csv("data.csv")

首先我试过这个

data <- as(mydata, "transactions")
## Error in asMethod(object) : 
## column(s) 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
## 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 
## 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 
## 49, 50, 51 not logical or a factor. Use as.factor, as.logical 
## or categorize first.

然后我尝试了这个

data <- sapply(mydata,as.factor)
data_1 <- as(data, "transactions")
## Error in t(as(from, "ngCMatrix")) :  Error in asMethod(object) :
## cannot coerce 'NA's to "nsparseMatrix"

我真的不知道该怎么做,请帮帮我。

我的数据看起来像

mydata[1:2,]

  id item_0 item_1 item_2 item_3 item_4 item_5 item_6 item_7 item_8 item_9 item_10

1  0      0      1      0      0      0      0      0      0      0      0       0
2  1      0      0      0      1      0      1      0      0      0      0       0

    item_11 item_12 item_13 item_14 item_15 item_16 item_17 item_18 item_19 item_20

1         0       0       0       0       0       0       0       0       0       1
2         0       1       0       0       0       1       0       0       0       0

    item_21 item_22 item_23 item_24 item_25 item_26 item_27 item_28 item_29 item_30

1         0       0       0       0       0       0       0       0       0       0
2         0       1       0       0       0       0       0       0       0       0

    item_31 item_32 item_33 item_34 item_35 item_36 item_37 item_38 item_39 item_40

1         0       0       0       0       0       1       0       0       0       0
2         0       0       0       0       0       0       0       0       0       0

    item_41 item_42 item_43 item_44 item_45 item_46 item_47 item_48 item_49

1         0       0       0       0       0       0       0       0       0
2         0       0       0       0       0       0       0       0       0
4

0 回答 0