library(tidyverse)
(raw1 <- tribble(~Month,~Date,~Day,~Mins,~Calories,~Type,
"March",16,"Monday","00:12:20",NA,"Running",
"March",17,"Tuesday","00:44:11",140,"Strength",
"March",19,"Thursday","00:15:42",NA,"Running",
"April",2, "Thursday","00:43:13",140,"Strength",
"April",5, "Sunday","00:30:00,65",NA,"Core",
"April",6, "Monday","00:30:09,90",NA,"Cardio") %>%
mutate(Month=as_factor(Month)))
(smry2 <- group_by(raw1,
Month) %>% summarise(
days=length(unique(Date)),
calorie_sum = sum(Calories,na.rm = TRUE)
))
empty_raw <- slice(raw1, 1) %>%
select(-Month) %>%
mutate_all(.funs = function(x) {
y <- NA
class(y) <- class(x)
y
})
(smry3 <- expand_grid(smry2,empty_raw))
(to_display <- bind_rows(raw1,smry3) %>% arrange(Month,Date))