Let's say I have a dataframe that looks like:
owner unit_id detail
abc123 002NH034 94847DT
abc123 002NH034 94868DT
abc123 002NH034 94889DT
abc123 112NH035 94899DT
abc123 112NH036
abc123 112NH037
I'm trying to roll up to the level of the first column, while counting the number of distinct values in the second column that have a value in the third column. So expected output would be:
abc123 2
I've tried a mix of sum, is.na, and a few other dplyr functions but am a little stuck. I've tried a variation of the following with random other functions but keep getting sums of all the rows.
df %>% group_by(owner) %>% summarise(unit_ids_with_detail = sum(!is.na(detail))