1

I am using Apriori Association rules in R with a database structured as the following. using the following code:

  library(arules)
    library(arulesViz)
# Convert data into dataframe with two factors
data3 <- as.data.frame(unclass(morse_code_reasonsv2),                    
                       stringsAsFactors = TRUE)
# applying appriori
    rules7 <- apriori(data3, parameter = list(support = 0.05,confidence = 0.5,minlen=2, maxlen=3), appearance=list(rhs=c("Firm's.global.reorganization=Yes"),
                                                                                                                   lhs=c("Delivery.time=Yes",
                                                                                                                      "Automation.of.production.process=Yes"),default="none"))

Using this formula I get the following error:

error in asMethod(object) : 
  Delivery.time=Yes is an unknown item label, Automation.of.production.process=Yes is an unknown item label

EDIT: data in dput:

structure(list(Firm.s.global.reorganization = structure(c(1L, 
2L, 1L, 2L, 2L), .Label = c("no", "yes"), class = "factor"), 
    Delivery.time = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("no", 
    "yes"), class = "factor"), Automation.of.production.process = structure(c(2L, 
    1L, 2L, 1L, 1L), .Label = c("no", "yes"), class = "factor"), 
    Poor.quality.of.offshored.production = structure(c(1L, 1L, 
    1L, 1L, 1L), .Label = c("no", "yes"), class = "factor"), 
    Made.in.effect = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("no", 
    "yes"), class = "factor"), Proximity.to.customers = structure(c(1L, 
    1L, 1L, 1L, 1L), .Label = c("no", "yes"), class = "factor")), row.names = c(NA, 
5L), class = "data.frame")
Jelle M
  • 11
  • 2
  • Please share data in a [reproducible format](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) such as a `dput()` and not an image so we can copy/paste into R for testing. – MrFlick Jul 18 '22 at 21:04
  • I have added the data! – Jelle M Jul 19 '22 at 07:36

1 Answers1

0

If you convert your data into transactions then you see that the item labels are different from what you specify in appearance (lowercase letters for yes/no and the ' is converted to a .). Use these labels and it should work.

trans <- transactions(data3)
itemLabels(trans)
 [1] "Firm.s.global.reorganization=no"          "Firm.s.global.reorganization=yes"        
 [3] "Delivery.time=no"                         "Delivery.time=yes"                       
 [5] "Automation.of.production.process=no"      "Automation.of.production.process=yes"    
 [7] "Poor.quality.of.offshored.production=no"  "Poor.quality.of.offshored.production=yes"
 [9] "Made.in.effect=no"                        "Made.in.effect=yes"                      
[11] "Proximity.to.customers=no"                "Proximity.to.customers=yes"      
Michael Hahsler
  • 2,965
  • 1
  • 12
  • 16