I would use indexing
# save all the "transactions" where iteamtype equals "a" to an object called F
f <- df[ df$itemType %in% "a" , "transaction" ]
#optional (look as f)
print(f)
print( unique(f))
# Subset to all the rows which equals one of the "transactions" stored in the object f
df[ df$transaction %in% unique( f ) , ]
3
solved Subset all rows by group by type