I'm a new R programmer with what is probably a very simple issue.
I have a dplyr summarize/spread snippet as follows:
enroll_data_eth_sum <- group_by(enroll_data_distinct, EMISEthnicity) %>%
summarize(freq = n()
) %>%
spread(EMISEthnicity, freq)
Which produces this table:
What I need is that table to be percentages of the row...not the values. I have tried a few things (like freq = (n=n()) / sum(n)), but this just gave all 1s (which upon reflection was probably correct).
Any thoughts? I know it's something simple...thank you!!
John
UPDATE: I tried the following based on Cedric's post:
enroll_data_eth_sum <- group_by(enroll_data_distinct, EMISEthnicity)
%>%
summarize(n = n()) %>%
mutate(freq = n / sum(n)) %>%
spread(EMISEthnicity, freq)
But that gave me this table:
The values are correct...but I need it all on one row. ??