Iam working on a project in R but can't figure out how to create grouped data based on the categorical variable (Occuptation with 10 factors) and Died( being a yes/no factor variable).
Ive looked at numerous articles but everytime I try to count the number of "yes" and "no" of a single column(Died) i get a dimension error
'data.frame': 2571 obs. of 4 variables:
$ Occupation: Factor w/ 10 levels "business/service",..: 3 2 2 2 2 2 2 2 2 5 ...
$ Education : Factor w/ 5 levels "iliterate","primary",..: 3 2 2 2 3 1 1 3 2 3 ...
$ Age : int 39 83 60 73 51 62 90 54 66 30 ...
$ Died : Factor w/ 2 levels "no","yes": 1 2 2 2 1 2 2 1 2 1 ...
this is the summary of my data. SO looking to group Each 10 of the occupation factors with the number of people died.
This was the code I was trying is:
dperoccu <- summarise(occu, count = n(), deaths = count(SuicideChina$Died, "yes"))
but produced the follwing error:
Error in UseMethod("group_by_") : no applicable method for 'group_by_' applied to an object of class "factor"