Search code examples
rgspapriori

Frequent Sequential Patterns


What would be the best way to get the sequential pattern for such data in R :

enter image description here

The idea is to get the frequency of letters in process 1,2, and 3. Is there GSP function that can do that ? any insight or tutorial is appreciated.


Solution

  • you can use an apply and table combo (provided you read your data into R):

    dat <- data.frame(process1 = c('A', 'B', 'A', 'A', 'C'), process2 = c('B', 'C', 'B', 'B', 'A'), process3 = c('C', 'C', 'A', 'B', 'B'))
    apply(dat, 2, table)
    #  process1 process2 process3
    #A        3        1        1
    #B        1        3        2
    #C        1        1        2
    

    apply iterates through the columns of dat (this is what argument 2 refers to) and applies table to each, which counts each unique element. see help pages for *apply family of functions for more info.

    d.b's solution above, lapply(dat, table), does the same thing but returns a list rather than a matrix.