-3

I need to create a running total for each day in excel or R Studio for this table and I cannot figure out how to do it. So for 2/28 it would start at 1 and then 2. Then for 2/27 it would start at 1 again and proceed down and so on restarting the total each day.

Date         Total
2/28/2018 
2/28/2018 
2/27/2018 
2/27/2018 
2/27/2018 
2/27/2018 
2/27/2018 
2/27/2018 
2/27/2018 
2/27/2018 
2/25/2018 
2/25/2018 
2/25/2018 
2/25/2018 
2/25/2018 
2/25/2018 
2/24/2018 
2/24/2018 
2/24/2018 
2/24/2018 
2/24/2018 
2/24/2018 
2/24/2018 
2/24/2018 
2/24/2018 
2/24/2018 
2/23/2018 
2/23/2018 
2/23/2018 
2/23/2018 
2/23/2018 
2/23/2018 
2/23/2018 
2/23/2018 
2/23/2018 

2 Answers2

2

You can use dplyr to do this.

library(dplyr)
data.frame(Date=rep(LETTERS[1:5], each=c(4))) %>% 
  group_by(Date) %>% 
  mutate(Total=seq_along(Date))

So in your case, replace the data.frame(...) with your data.

drmariod
  • 11,106
  • 16
  • 64
  • 110
0

You can do it using dplyr

Date <- c("2/28/2018","2/28/2018","2/27/2018","2/27/2018","2/25/2018")  

df <- data.frame(Date)

df <- df %>% 
 group_by(Date) %>% 
 mutate(Total = seq_along(Date)) %>% 
 as.data.frame()
Neil
  • 7,937
  • 22
  • 87
  • 145