-3

I have a data set that looks like this:

                                       Company Year                       Name   Position Gender     Sales     rdb rdbpersal Directors Executives Employees
1          Johnson & Johnson 2016          Dominic J. Caruso  Executive      0  71891000 9095000     12,65         9          9    126400
2          Johnson & Johnson 2016              Joaquin Duato  Executive      0  71891000 9095000     12,65         9          9    126400
3          Johnson & Johnson 2016            Peter M. Fasolo  Executive      0  71891000 9095000     12,65         9          9    126400
4          Johnson & Johnson 2015                Alex Gorsky  Executive      0  71891000 9095000     12,65         9          9    126400
5          Johnson & Johnson 2015             Jorge Mesquita  Executive      0  71891000 9095000     12,65         9          9    126400
6          Johnson & Johnson 2015         Sandra E. Peterson  Executive      1  71891000 9095000     12,65         9          9    126400
7          Johnson & Johnson 2015                Gary Pruden  Executive      0  71891000 9095000     12,65         9          9    126400
8          Johnson & Johnson 2014            Paulus Stoffels  Executive      0  71891000 9095000     12,65         9          9    126400
9          Johnson & Johnson 2014         Michael H. Ullmann  Executive      0  71891000 9095000     12,65         9          9    126400
1

I would like to plot the number of male/female executives over the years. Since I only have a dummy variable, I would like to count the amount of "0" or "1" for each year and company and draw them.

How can I do something like sum(data$Gender) "IF" (data$Year=same) "AND" (data$Company=same) ?

Jaap
  • 81,064
  • 34
  • 182
  • 193
of_horse
  • 9
  • 5

1 Answers1

1
library(dplyr)

df %>% group_by(company,year) %>% summarise(n.gender = sum(gender))

The data you provided only has one company. This will give you sum of "1" for each group.

MLEN
  • 2,162
  • 2
  • 20
  • 36