R Markdown Presentation

##Q1

data<-as_tibble(data)

##Q2

data %>% select(occupation,age) %>% group_by(occupation) %>% summarise(averge_profession=mean(age))
## # A tibble: 21 × 2
##    occupation    averge_profession
##    <chr>                     <dbl>
##  1 administrator              38.7
##  2 artist                     31.4
##  3 doctor                     43.6
##  4 educator                   42.0
##  5 engineer                   36.4
##  6 entertainment              29.2
##  7 executive                  38.7
##  8 healthcare                 41.6
##  9 homemaker                  32.6
## 10 lawyer                     36.8
## # ℹ 11 more rows

##Q3

data %>% select(occupation,age) %>% group_by(profession=occupation) %>% summarise(âges_minimum=min(age),âges_maximum=max(age))
## # A tibble: 21 × 3
##    profession    âges_minimum âges_maximum
##    <chr>                <dbl>        <dbl>
##  1 administrator           21           70
##  2 artist                  19           48
##  3 doctor                  28           64
##  4 educator                23           63
##  5 engineer                22           70
##  6 entertainment           15           50
##  7 executive               22           69
##  8 healthcare              22           62
##  9 homemaker               20           50
## 10 lawyer                  21           53
## # ℹ 11 more rows

##Q4

data %>% select(profession=occupation,gender,age) %>% group_by(profession,gender) %>% summarise(mean(age))
## `summarise()` has grouped output by 'profession'. You can override using the
## `.groups` argument.
## # A tibble: 41 × 3
## # Groups:   profession [21]
##    profession    gender `mean(age)`
##    <chr>         <chr>        <dbl>
##  1 administrator F             40.6
##  2 administrator M             37.2
##  3 artist        F             30.3
##  4 artist        M             32.3
##  5 doctor        M             43.6
##  6 educator      F             39.1
##  7 educator      M             43.1
##  8 engineer      F             29.5
##  9 engineer      M             36.6
## 10 entertainment F             31  
## # ℹ 31 more rows

##Q5

data %>% select(profession=occupation,gender) %>% group_by(profession) %>% filter(gender=='M') %>% summarise(ratio=n()/nrow(.)) %>% arrange(desc(ratio))
## # A tibble: 21 × 2
##    profession     ratio
##    <chr>          <dbl>
##  1 student       0.203 
##  2 educator      0.103 
##  3 other         0.103 
##  4 engineer      0.0970
##  5 programmer    0.0896
##  6 administrator 0.0642
##  7 executive     0.0433
##  8 scientist     0.0418
##  9 technician    0.0388
## 10 writer        0.0388
## # ℹ 11 more rows