Applying a function to groups when missing values

Hi all, I have a huge table made in this way
ID1 ID2 Date Occurrences
1 1 2015-5 9
1 2 2015-5 11
1 2 2015-6 1
1 43 2015-8 2
2 3 2015-7 40
The primary key of the table is the triple (ID1,ID2,Date).
Now if I want to apply a function to sum how many occurrences a single ID1 has per month, getting rid of ID2, I can use:
varfun(@sum,data,'InputVariables','Occurrences', GroupingVariables',{'ID1','Date'});
is there a way to expand the grouping such that the dates considered are the all unique values in the Date column? In other words, the month 2015-7 is not present for ID1 = 1, but I would like to get a 0 instead of no row with that value because it is not present after grouping for ID1 = 1

Answers (1)

I kinda solved the problem by making an outer left join with a full table of ID1 and Date. It is not very elegant but it works

This question is closed.

Asked:

on 24 Sep 2018

Closed:

on 20 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!