How to do it...

Perform the following steps to create transactions with temporal information:

  1. First, you need to install and load the arulesSequences package:
        > install.packages("arulesSequences")
        > library(arulesSequences)  
  1. You can first create a list with purchasing records:
    > tmp_data=list(c("A"),
    +                c("A","B","C"),
    +                c("A","C"),
    +                c("D"),
    +                c("C","F"),
    +                c("A","D"),
    +                c("C"),
    +                c("B","C"),
    +                c("A","E"),
    +                c("E","F"),
    +                c("A","B"),
    +                c("D","F"),
    +                c("C"),
    +                c("B"),
    +                c("E"),
    +                c("G"),
    +                c("A","F"),
    +                c("C"),
    +                c("B"),
    +                c("C"))  
  1. You can then turn the list into transactions and add temporal information:
 > names(tmp_data) = paste("Tr",c(1:20), sep = "") > trans = as(tmp_data,"transactions") > transactionInfo(trans)$sequenceID=c(1,1,1,1,1,2,2,2,2,3,3,3,3,3,4 ...

Get Machine Learning with R Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.