mardi 30 juin 2015

Finding patterns across rows of data.table in R

I am trying to find patterns across rows of a data.table while still maintaining the linkages of data across the rows. Here is a reduced example:

Row ID Value
1   C  1000
2   A  500
3   T  -200
4   B  5000
5   T  -900
6   A  300

I would like to search for all instances of "ATB" in successive rows and output the integers from the value column. Ideally, I want to bin the number of instances as well. The output table would look like this:

String Frequency Value1 Value2 Value 3
ATB      1        500   -200    5000
CAT      1        1000   500    -200

Since the data.table packages seems to be oriented towards providing operations on a column or row-wise basis I thought this should be possible. However, I haven't the slightest idea where to start. Any pointers in the right direction would be greatly appreciated.

Thanks!

Aucun commentaire:

Enregistrer un commentaire