Search code examples
runique

Extracting matching unique value


I have the following table:

 > head (data6)
                                                                 verb_object SESSION_ID transactionID sequenceID eventID items
    1:                               34D89F927092290A5DA9B108F7020C19 SELECT   36652675          2058   36652675       1   OV1
    2: 15873DB37BF80750C70B68A8778B9DC01D548B6D06E3BF92CADAFF289B3FCAEE CALL   38763251            90   38763251       1   OV2
    3: D6941F85A1763F1F2D27B8F032D6411C86D4A5200512D65F381052C7D42BF57F CALL   40257471            63   40257471       1   OV3
    4:                               E768D36C813FD14157B06474F345EAFC SELECT   40897086         39475   40897086       1   OV4
    5: 15873DB37BF80750C70B68A8778B9DC01D548B6D06E3BF92CADAFF289B3FCAEE CALL   40907760            57   40907760       1   OV2
    6:                               8067DE5FF5089BE6EC9D213F42525FC3 SELECT   40928334         29697   40928334       1   OV5

I would like to extract a dataframe that for each unique (verb_object) the appropriate items value will be represented as followed:

> U1

                                                           verb_object items
                               34D89F927092290A5DA9B108F7020C19 SELECT   OV1
 15873DB37BF80750C70B68A8778B9DC01D548B6D06E3BF92CADAFF289B3FCAEE CALL   OV2
 D6941F85A1763F1F2D27B8F032D6411C86D4A5200512D65F381052C7D42BF57F CALL   OV3
                               E768D36C813FD14157B06474F345EAFC SELECT   OV4
                               8067DE5FF5089BE6EC9D213F42525FC3 SELECT   OV5

Solution

  • You can simply do (it seems that you have a data.table as input, I note it dt):

    unique(dt[,c("verb_object", "items"), with=F])