'How can I divide the frequency found from two different summarise function in R?
How can I divide the frequency found from two different summaries?
The code of first summary :
brfss2013 %>%
filter( !is.na(income2), Depression == "SignsOfDepression") %>%
group_by(X_state) %>%
summarise(depressed=n())
Depressed frequency state wise
The code of second summary:
brfss2013 %>%
filter( !is.na(income2)) %>%
group_by(X_state) %>%
summarise(total=n())
Now I want to find the relative frequency of "depressed" and "total" state-wise where I divide "depressed"/ "total".
I tried to use the following code:
brfss2013 %>%
filter( !is.na(income2)) %>%
group_by(X_state) %>%
summarise(ratio = depressed/total)
But it does not work.
Can somebody please help me to find the state-wise relative frequency.
Solution 1:[1]
brfss2013 %>%
filter( !is.na(income2) ) %>%
group_by(X_state) %>%
summarise(depressed=sum(Depression == "SignsOfDepression"), total=n()) %>%
mutate(ratio=depressed/total)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | langtang |
