In the below data I want to see two metric for each week:
- how many unique household - individual combination are there
- how many unique household - individual combination spent on that week
For week 1 there are 4 unique household - individual combination of whom 3 had spent and in week 2, 3 unique combination of whom 2 were spent
week total present
1 4 3
2 3 2
Below is what I did but not sure how to add the 2nd calculation here
data %>%
group_by(week) %>%
summarise(total = n_distinct(household, individual))
Here is the Sample dataset:
library(dplyr)
data <- data.frame(week = c(1,1,1,1,1,2,2,2,2),
household = c(1001,1001,1001,1001,1002,1001,1001,1001,1001),
individual = c(1,1,2,3,2,1,2,2,3),
Spent = c(20,30,90,NA,30,40,50,10,NA))
