Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. aggregate(paste(ID , Date) ~ ID + Date, data = df, FUN = length)
  2.  
  3. library(dplyr)
  4. df %>% group_by(ID, Date) %>% summarise(PurchaseCount = n())
  5. df %>% group_by(ID, Date) %>% tally(name="PurchaseCount")
  6. df %>% group_by(ID, Date) %>% count(name="PurchaseCount")
  7. df %>% group_by(ID, Date) %>% add_tally(name="PurchaseCount")
  8. df %>% group_by(ID, Date) %>% add_count(name="PurchaseCount")
  9.  
  10. library(data.table)
  11. setDT(df)[, PurchaseCount:=.N, by = list(ID, Date)]
  12.  
  13. library(sqldf)
  14. sqldf("SELECT ID, Date, COUNT(*) as PurchaseCount
  15. FROM df
  16. GROUP BY Date, ID")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement