I have the following dataset:
id_municipio year Vivo Claro TIM Oi Algar Sercomtel MVNO
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1100015 2009 65.4 13.0 28.2 90.8 0 0 0
2 1100023 2009 775. 154. 334. 1076. 0 0 0
3 1100031 2009 35.2 6.98 15.2 48.8 0 0 0
4 1100049 2009 634. 126. 273. 880. 0 0 0
5 1100056 2009 122. 24.2 52.6 169. 0 0 0
6 1100064 2009 135. 26.7 58.2 187. 0 0 0
I want to create another column by "id_municipio"
and "year"
which add 1 if the remaining columns have a value bigger than 0. Here is what a I to have:
id_municipio year Vivo Claro TIM Oi Algar Sercomtel MVNO total Providers
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 1100015 2009 65.4 13.0 28.2 90.8 0 0 0 197. 0
2 1100023 2009 775. 154. 334. 1076. 0 0 0 2339. 0
3 1100031 2009 35.2 6.98 15.2 48.8 0 0 0 106. 0
4 1100049 2009 634. 126. 273. 880. 0 0 0 1912. 0
5 1100056 2009 122. 24.2 52.6 169. 0 0 0 368. 0
6 1100064 2009 135. 26.7 58.2 187. 0 0 0 407. 0
I know it would be something like this but I am stuck:
library(dplyr)
dataset %>% group_by(id_municipio, year) %>% mutate(Providers =...)