r - dplyr - group_by and count if variable satisfies condition -
i've got problem seems quite simple conceptually yet i'm having hard time accomplishing in r (and examples i've found online many (using dplyr) yet not seem @ i'm looking for). here's example below:
i've got 3 variables: response (factor), type (factor), , status (factor). basically, i'm trying figure out how many times (frequency) particular response appears each type if status equals 1. responses between 0-10. below example dataframe:
response type status 5 0 5 1 2 0 0 0 6 1 1 1 9 0 3 1 4 1 0 1 9 0 1 0 0 1 7 0 5 b 1 4 b 1 4 b 1 8 b 0 7 b 1 8 b 0 2 b 0 0 b 1 10 b 0 3 b 0 1 b 0 9 b 0 4 b 1 1 b 1
the end-result i'm looking displayed below, responsescale shows full range of response options available (0-10), , count displays frequency particular response appear given responsescale.
type responsescale count 0 2 1 1 2 0 3 1 4 1 5 1 6 1 7 0 8 0 9 0 10 0 b 0 1 b 1 1 b 2 0 b 3 0 b 4 3 b 5 1 b 6 0 b 7 1 b 8 0 b 9 0 b 10 0
i've tried using group_by in dplyr without success (i couldn't frequency counts display type--output displayed counts overall collapsed across type). more importantly, i'm not sure how incorporate status equals 1 part want within dplyr example.
any help/pointers appreciated--thanks!
Comments
Post a Comment