0

I have a question, I'm learning to use group_by() and summarise() in the R. But, I stopped at a question in the book I'm studying.

Follow: "How many senators did each party have? Which one had more? Which ones had the least? Tip use: group_by (), summarize () and n_distinct ()"

The data set seems like it's:

enter image description here

I have tried to do like this:

    senators <- senado %>% group_by(Party) %>% summarise(num_senators = n_distinct(senado$SenatorUpper))

But, I don't have success.

zeehio
  • 4,023
  • 2
  • 34
  • 48
BrenoShelby
  • 21
  • 1
  • 5
  • Please do not post an image of code/data/errors: it cannot be copied or searched (SEO), it breaks screen-readers, and it may not fit well on some mobile devices. Ref: https://meta.stackoverflow.com/a/285557 (and https://xkcd.com/2116/). Please just include the code, console output, or data (e.g., `dput(head(x))` or `data.frame(...)`) directly. – r2evans Jun 05 '20 at 02:57
  • *"but, I don't have success"* ... errors, warnings, or incorrect output would be best shown to use (verbatim). If just incorrect output, it might still be informative. (More-so because we don't have sample data on which we can try the code ourselves.) – r2evans Jun 05 '20 at 02:59
  • 1
    Don't use `$` in `dplyr` pipes . Try `senado %>% group_by(Party) %>% summarise(num_senators = n_distinct(SenatorUpper))` – Ronak Shah Jun 05 '20 at 03:04

0 Answers0