I am looking for the best method to go from a sequence of events such as

time event
1 a
2 b
3 a
4 b
5 c
6 d
7 c
8 d
9 e

Where each letter corresponds to a certain event that occurs at a time. I want to reduce the number of events by aggregating frequently occurring events into a new event. A possible solution data set would look like,

1 a'
2 a'
3 a'
4 a' 
5 b'
6 b'
7 b'
8 b'
9 e

where the clusters are created because they occur in a sequence following each other.

I was looking at the text mining algorithms in R with tm or RNA sequenceing with edgeR. But I have no experience in this so I was hoping that someone can shed me some light on a common approach for this type of problems.

  • 1
    $\begingroup$ Lots of details and context is missing. It is unclear what those sequences are and what does it mean to transform. A wild wild guess: you have a set of sequences with corresponding output sequences. RNN can learn such transoframation (similar to machine translation, e.g. from english to french). $\endgroup$ Oct 28, 2015 at 20:47
  • $\begingroup$ Are you wanting to aggregate events by some common features of their "type" (independent of where they appear in the sequence) e.g. you consider a' in your example to cover a and b because they are similar in some way? Or are you wanting to cluster events by when they occur in the sequence e.g. you are combining a and b because they occur together? $\endgroup$ Oct 29, 2015 at 10:09
  • $\begingroup$ They occur in sequence. Not because they have any kind of resemblance. $\endgroup$
    – Stereo
    Oct 29, 2015 at 12:58

1 Answer 1


You may use ngrams to get the frequent sequences of you events.

Here a little example

 seq <- "ababcdcde"
 textcnt(seq, method="ngram", n=3L, decreasing=TRUE)

   _   a  ab   b   c  cd   d  _a _ab aba abc  ba bab  bc bcd cdc cde  dc dcd  de de_   e  e_ 
   2   2   2   2   2   2   2   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1   1

Select the longest and most frequent ngram, here ab and cd. You may also trade off the length and frequency to get maximal compression. The n parameter limits the length of the ngram.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.