Kristian Vybiral
Kristian Vybiral

Reputation: 539

R unable to find an inherited method for function 'itemFrequency' for signature '"data.frame"'

I have a df named 'a' and with the following command:

 freq <- itemFrequency(a, weighted = FALSE)

which gives an

error:unable to find an inherited method for function 'itemFrequency' for signature '"data.frame"'

There doesn't seem to be any hint as to what this is anywhere online. R documentations states that a must be an object, which a data frame is.

Found: df has to be converted into item matrix like so:

a1 <- as(a, "transactions")

and then used in itemFrequency.

Upvotes: 0

Views: 4399

Answers (1)

Moh K
Moh K

Reputation: 514

I see that you are trying to implement Apriori algorithm.

To find the itemFrequency of the items in your data set

itemFrequency(mydata) Error in function (classes, fdef, mtable) : unable to find an inherited method for function "itemFrequency", for signature "data.frame"

Solution: step1. load the necessary packages and library like arules, arulesViz step2. Let say you trying to bring votes data and you need to read the data as transactions

votes <- read.transactions("~/Desktop/votes.csv") if you just write votes you will have a summary of your transactions as follow votes transactions in sparse format with 435 transactions (rows) and 342 items (columns)

Now you can easily find the itemFrequency

itemFrequency(votes) Here is a sample image

itemFrequency(votes) democrat 245
republican 345

Hope this will help!

Upvotes: 1

Related Questions