Search code examples
rdatedplyrgroup-bycount

How to count the number of occurences of an event in a date R studio


I want to know how I can extract the number of times events occured for each date. My dataset looks like this:

Date            burstID
2018-09-18      1
2018-09-18      2
2018-09-18      3
2018-09-18      4

Basically for each date I need to count the number of times we have bursts with burstID. I've tried multiple things like:

numberofburst <- df %>% group_by(Date) %>% count(burstID)

But it returns a new column n that specifies the number of burst per ID (always 1), which is not what I mean.

Any help please ?


Solution

  • Do you want this for counting?

    df %>%
        summarise(count = n(), .by = Date)
    

    which gives

            Date count
    1 2018-09-18     4