Search code examples
raprioriarules

Search by transaction id in transaction set in R


I am working on a marketbasket analysis with arules in R, my transaction set has transaction id, like in the example.

screen shot of example:

enter image description here

I have a need to search items in the transaction set by transaction id, like, if I search for 0002, it should list out all the item related to that transaction id.


Solution

  • if I understood you correctly, and trans1 is a transaction object, you can try:

    (Grep will get you all transactions containing the string)

    inspect(trans1[grep("0002",trans1@itemsetInfo$transactionID)])
    

    update: To get exact match try:

     inspect(trans1[ trans1@itemsetInfo$transactionID=='0002',])