rarulesmarket-basket-analysis

How to get the list of items in a transaction in package arules


I know you can see the content of each transaction using inspect and then extract the items yourself, but is there a convenient way to get a list of all items which belong to a transaction?


Solution

  • a_list <- list( # Create example data
          c("a","b","c"),
          c("a","b"),
          c("a","b","d"),
          c("c","e"),
          c("a","b","d","e")
          )
    
    ## set transaction names
    names(a_list) <- paste("Tr",c(1:5), sep = "")
    a_list
    
    ## coerce into transactions
    trans1 <- as(a_list, "transactions")
    
    ## analyze transactions
    summary(trans1)
    image(trans1)  
    
    # if you want an actual list structure:
    trans1 <- as(a_list, "list")
    

    This is the plot of it from image():

    enter image description here

    Now with a bigger transactions object:

    data("Adult")
    adult_list <- as(Adult, "list")