Count number of weekly events per artist in R data.table

Viewed 98

My goal is to create a data.table which shows the total number of events per week per artist. Furthermore, I would also like to add two columns which specify the number of events and the number of concerts given per artist in a particular week.

My data.table looks like this:

 Year_week  artist_id   type    event_id
 17\2       464836     Concert  54446
 17\2       4234234    Festival 6654
 17\3       89543      Concert  5321
 17\3       55211      Concert  85642
 17\4       32167      Concert  43222
 17\4       9876       Concert  13131

I already tried to aggregate by week for the total number of events. However, as I am quite new to R I have the feeling what I am doing is not the right way.

#number of events per week per artist
 USevents_weekly_total = USevents[, list(number_of_events = .N (unique(event_id))),
                                      by=c('Year_week', 'artist_id')]

What would be the most convenient way to do this in data.table?

1 Answers
Related