I've used the arrange and mutate combination to do additions based on groupings. For example, I've used the following:
master_df <-group_by(master_df,asof_dt)
mutate(master_df,tot_flag=ls_flag)
This groups my data frame master_df by asof_dt, and then creates tot_flag and adds ls_flag by date.
However, my ls_flag column contains NA's.
I would like to do the following: 1) find out how to add the ls_flag, ignoring any NA's 2) find out how to add the total number of NA's per day.
Here is the full example:
asof_dt<-c("2014-10-01","2014-10-01","2014-10-01","2014-10-02","2014-10-02","2014-10-02")
ls_flag<-c(1,1,NA,NA,1,1)
master_df<-data.frame(asof_dt,ls_flag)
master_df <-group_by(master_df,asof_dt)
mutate(master_df,tot_flag=sum(ls_flag))
Thank you very much!