Is it possible to calculate in r the number of days and count of b in var r from the following table:
id r s t u
1 a 100 1 27-06-2017
1 a 200 0 29-06-2017
1 b 300 0 01-07-2017
2 a 500 1 12-06-2017
3 b 100 0 02-07-2017
3 a 600 1 02-07-2017
4 a 200 0 12-06-2017
4 a 300 1 15-06-2017
4 b 200 0 18-06-2017
4 a 100 0 01-07-2017
5 a 200 0 04-06-2017
grouped by unique ID
where the condition = when r = b, sum of s >= sum of s when t = 1?