Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

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

like image 948
user3292373 Avatar asked Feb 17 '14 15:02

user3292373


2 Answers

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")
like image 79
user1570017 Avatar answered Oct 21 '22 09:10

user1570017


This problem is caused by library installed incomplete(I guess it might put the wrong name(version) in the pack of arulesViz).

You can download https://cran.rstudio.com/bin/windows/contrib/3.3/seriation_1.2-1.zip manually,then use "r-studio menu -> tools -> install packages.." to install above zip file downloaded from the site.

Then try to redo install.packages("arulesViz") and library(arulesViz), it will be workable. Done.

like image 27
Vincent Chang Avatar answered Oct 21 '22 07:10

Vincent Chang