Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

r - Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double'

I am applying Aprior algorithm, and while plotting there is an error.

I have installed packages arules and arulesviz.

The data has 3 attributes . Two were factorized and one attribute was not factorized. I have taken that attribute attribute separately and applied factor function. The code is below:

New_Train_Wifi = read.xlsx("D:/Train_Test.xls",1)

str(New_Train_Wifi)
'data.frame':   2201 obs. of  3 variables:
 $ Wifi_ID: Factor w/ 4 levels "1st","2nd","3rd",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ Store  : Factor w/ 5 levels "Book_Store","Clothing",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ Mac_ID : num  125 125 125 125 125 125 125 125 125 125 ...

A <- as.factor(Test_ARM_ABC$Wifi_ID)
C <- as.factor(New_Train_Wifi$Mac_ID)
New_Train_Wifi$MacID <- NULL
New_Train_Wifi$MacID <- C
New_Train_Wifi$Mac_ID <- NULL

class(New_Train_Wifi)
[1] "data.frame"
[1] "Wifi_ID" "Store"   "MacID" 
str(New_Train_Wifi)
'data.frame':   2201 obs. of  3 variables:
 $ Wifi_ID: Factor w/ 4 levels "1st","2nd","3rd",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ Store  : Factor w/ 5 levels "Book_Store","Clothing",..: 3 3 3 3 3 3 3 3 3 3 ...
 $ MacID  : Factor w/ 6 levels "100","125","254",..: 2 2 2 2 2 2 2 2 2 2 ...

rules <- apriori(New_Train_Wifi)
inspect(rules)
rules <- apriori(New_Train_Wifi, parameter = list(minlen = 2, supp = 0.10, conf = 0.8), 
                 appearance = list(rhs = c("Wifi_ID=1st", "Wifi_ID=2nd", "Wifi_ID=3rd", 
                 "Wifi_ID=4th"), default="lhs"), control = list(verbose = F))

> inspect(rules.sorted)

#/*Now wen I give below statement in r console */
> plot(rules)
Error in as.double(y) : 
 cannot coerce type 'S4' to vector of type 'double'

Above statement is the error I tried to but couldn't resolve . If anyone can resolve it, I will be really grateful.

The site that I referred to: http://www.rdatamining.com/examples/association-rules

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had this issue too and then realized that I forgot to load the library with

library(arulesViz)

after installing the package with:

install.packages("arulesViz")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...