Hello, I´m stuck trying to summarize my data with some filters.
I have 3 differents filters:
Var_1 >1000,
Var_1 >500 & Var_1 <1000,
Var_1 <500
After filtering I want the percentage of another variable (Var_2) of each group over the total of Var_2.
Now I´m doing this. It has multiple steps and I know it is not the best way.
My_Data %>%
filter(Var_1 >= 1000) %>%
summarize (Percentage_Var_1_greater_1000 = sum(Var_2))
Total_Sum_Var_2 <- sum(My_Data$Var_2)
My_Data$Percentage_Var_1_greater_1000 / My_Data$Total_Sum_Var_2
Then the same code changing the filterin for Var_1 >500 & Var_1 <1000
And after that the same again filtering for Var_1 <500)
It kind of works but isn´t a nice code. Any help of how to put it all together?