0

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"
Sotos
  • 51,121
  • 6
  • 32
  • 66
rsteward
  • 51
  • 4
  • household Secondary 39 no, this is the layout of the data in my table, columns being Occupation, Education, age, died respectively if that helps – rsteward Aug 27 '19 at 08:39
  • Hi again. It actually does not really help. Please go through the links I gave you and format your question correctly. You can create reproducible example via `dput` – Sotos Aug 27 '19 at 08:49
  • Hi sorry iam very new, read the articles and editied it, hopefully this is more helpful – rsteward Aug 27 '19 at 11:03
  • 1
    What is `summary`? Are you using `dplyr`? Why don't you just do `occu %>% group_by(Occupation, Died) %>% count()`? – Sotos Aug 27 '19 at 11:12
  • THanks this worked, was using dplyr, can i ask what %>% does for curiosity ? – rsteward Aug 27 '19 at 12:52
  • Check [this link](https://stackoverflow.com/questions/24536154/what-does-mean-in-r) – Sotos Aug 27 '19 at 12:55

0 Answers0