I have a dataframe:
ID SUB_ID Action
1 NA Preparate1
1 NA Preparate2
1 A Open
1 A Download
1 A Close
1 B Open
1 B Search
1 B Download
1 B Close
2 AA Open
2 AA Download
2 AA Close
2 BB Open
2 BB Search
2 BB Filter
2 BB Close
3 C Open
3 C Search
3 C Filter
3 C Close
I want to get table with ID and number of SUB_ID per ID and number of "Download" in column Action. So, desired result is:
ID SUB_ID_n Download_n
1 2 2
2 2 1
3 1 0
How could i do that? As you see there are sometimes rows with NA in SUB_ID. I don't want to count those NA as additional SUB_ID within ID.
I have tried this but its counting NA in SUB_ID:
setDT(df)[, .(SUB_ID_n = uniqueN(SUB_ID),
Download_n = sum(Action == 'Download')), ID]