Introduction:

The titanic dataset contains data on 887 Titanic passengers, including each passenger’s survival status, embarkation location, cabin class, and sex.

Tasks

  • Load the dataset in titanic.csv as titanic.
  • Create a new data frame, firstSouth, by subsetting titanic to include instances where a passenger is in the first class cabin (pclass feature is 1) and boarded from Southampton (embarked feature is S).
  • Create a new data frame, secondThird, by subsetting titanic to include instances where a passenger is either in the second (pclass feature is 2) or third class (pclass feature is
    1. cabin.

Create bar charts for the following:

  • Passengers in first class who embarked in Southampton grouped by sex

  • Passengers in second and third class grouped by survival status alive


Task 1: Load titanic dataset & view first 10 rows

##    survived pclass    sex age sibsp parch    fare embarked  class   who
## 1         0      3   male  22     1     0  7.2500        S  Third   man
## 2         1      1 female  38     1     0 71.2833        C  First woman
## 3         1      3 female  26     0     0  7.9250        S  Third woman
## 4         1      1 female  35     1     0 53.1000        S  First woman
## 5         0      3   male  35     0     0  8.0500        S  Third   man
## 6         0      3   male  NA     0     0  8.4583        Q  Third   man
## 7         0      1   male  54     0     0 51.8625        S  First   man
## 8         0      3   male   2     3     1 21.0750        S  Third child
## 9         1      3 female  27     0     2 11.1333        S  Third woman
## 10        1      2 female  14     1     0 30.0708        C Second child
##    adult_male deck embark_town alive alone
## 1        TRUE      Southampton    no FALSE
## 2       FALSE    C   Cherbourg   yes FALSE
## 3       FALSE      Southampton   yes  TRUE
## 4       FALSE    C Southampton   yes FALSE
## 5        TRUE      Southampton    no  TRUE
## 6        TRUE       Queenstown    no  TRUE
## 7        TRUE    E Southampton    no  TRUE
## 8       FALSE      Southampton    no FALSE
## 9       FALSE      Southampton   yes FALSE
## 10      FALSE        Cherbourg   yes FALSE

Task 2: Create data frame as “firstSouth” that include first class passengers who embarked in Southampton

##    survived pclass    sex age sibsp parch     fare embarked class   who
## 4         1      1 female  35     1     0  53.1000        S First woman
## 7         0      1   male  54     0     0  51.8625        S First   man
## 12        1      1 female  58     0     0  26.5500        S First woman
## 24        1      1   male  28     0     0  35.5000        S First   man
## 28        0      1   male  19     3     2 263.0000        S First   man
## 36        0      1   male  42     1     0  52.0000        S First   man
## 56        1      1   male  NA     0     0  35.5000        S First   man
## 63        0      1   male  45     1     0  83.4750        S First   man
## 84        0      1   male  28     0     0  47.1000        S First   man
## 89        1      1 female  23     3     2 263.0000        S First woman
##    adult_male deck embark_town alive alone
## 4       FALSE    C Southampton   yes FALSE
## 7        TRUE    E Southampton    no  TRUE
## 12      FALSE    C Southampton   yes  TRUE
## 24       TRUE    A Southampton   yes  TRUE
## 28       TRUE    C Southampton    no FALSE
## 36       TRUE      Southampton    no FALSE
## 56       TRUE    C Southampton   yes  TRUE
## 63       TRUE    C Southampton    no FALSE
## 84       TRUE      Southampton    no  TRUE
## 89      FALSE    C Southampton   yes FALSE
## # A tibble: 1 × 3
## # Groups:   pclass [1]
##   pclass female  male
##    <int>  <int> <int>
## 1      1     48    79

Task 3: Create data frame as “secondThird” that include instances where a passenger is in either second or third class

##    survived pclass    sex age sibsp parch    fare embarked  class   who
## 1         0      3   male  22     1     0  7.2500        S  Third   man
## 3         1      3 female  26     0     0  7.9250        S  Third woman
## 5         0      3   male  35     0     0  8.0500        S  Third   man
## 6         0      3   male  NA     0     0  8.4583        Q  Third   man
## 8         0      3   male   2     3     1 21.0750        S  Third child
## 9         1      3 female  27     0     2 11.1333        S  Third woman
## 10        1      2 female  14     1     0 30.0708        C Second child
## 11        1      3 female   4     1     1 16.7000        S  Third child
## 13        0      3   male  20     0     0  8.0500        S  Third   man
## 14        0      3   male  39     1     5 31.2750        S  Third   man
##    adult_male deck embark_town alive alone
## 1        TRUE      Southampton    no FALSE
## 3       FALSE      Southampton   yes  TRUE
## 5        TRUE      Southampton    no  TRUE
## 6        TRUE       Queenstown    no  TRUE
## 8       FALSE      Southampton    no FALSE
## 9       FALSE      Southampton   yes FALSE
## 10      FALSE        Cherbourg   yes FALSE
## 11      FALSE    G Southampton   yes FALSE
## 13       TRUE      Southampton    no  TRUE
## 14       TRUE      Southampton    no FALSE
## # A tibble: 2 × 3
## # Groups:   pclass [2]
##   pclass    no   yes
##    <int> <int> <int>
## 1      2    97    87
## 2      3   372   119

Create bar charts for the following:

First class passengers who embarked in Southampton grouped by sex.


Passengers in second and third class grouped by survival status alive: