I have a dataframe with Transaction ID and Product Name as columns. I'm trying to create a 3rd column which gives me the count of Transaction ID's. The final dataframe should look as shown below.
TID Product Orders
100 iPhone 2
100 Samsung 2
101 Lenovo 3
101 iPad 3
101 Galaxy 3
102 iPhone 1
103 HTC 1
I tried using the length function, but that gives me the length of the entire column but not individual TIDs.
df$Orders <- length(df$Tid)
I also tried using the sqldf function as shown. But that gives only distinct values of TID.
test <- sqldf("Select TID, count(TID) as Orders, Product from df Group By TID")