Titanic = read.csv("Train.csv")
class(Titanic)
[1] "data.frame"
Titanic = as_tibble(Titanic)
glimpse(Titanic, width = 50)
Observations: 891
Variables: 12
$ PassengerId [3m[38;5;246m<int>[39m[23m 1, 2, 3, 4, 5, 6, 7, 8, 9...
$ Survived [3m[38;5;246m<int>[39m[23m 0, 1, 1, 1, 0, 0, 0, 0, 1...
$ Pclass [3m[38;5;246m<int>[39m[23m 3, 1, 3, 1, 3, 3, 1, 3, 3...
$ Name [3m[38;5;246m<fct>[39m[23m "Braund, Mr. Owen Harris"...
$ Sex [3m[38;5;246m<fct>[39m[23m male, female, female, fem...
$ Age [3m[38;5;246m<dbl>[39m[23m 22, 38, 26, 35, 35, NA, 5...
$ SibSp [3m[38;5;246m<int>[39m[23m 1, 1, 0, 1, 0, 0, 0, 3, 0...
$ Parch [3m[38;5;246m<int>[39m[23m 0, 0, 0, 0, 0, 0, 0, 1, 2...
$ Ticket [3m[38;5;246m<fct>[39m[23m A/5 21171, PC 17599, STON...
$ Fare [3m[38;5;246m<dbl>[39m[23m 7.2500, 71.2833, 7.9250, ...
$ Cabin [3m[38;5;246m<fct>[39m[23m , C85, , C123, , , E46, ,...
$ Embarked [3m[38;5;246m<fct>[39m[23m S, C, S, S, S, Q, S, S, S...
# Different variable name
Titanic <- rename(Titanic, # data frame
Departure_Point = Embarked) # new name = old name
# Dealing with missing values - dplyr way
Titanic <- mutate(Titanic, Departure_Point = na_if(Departure_Point, ""))
# Different levels
Titanic$Departure_Point <- recode(Titanic2$Departure_Point,
"C" = "Cherbourg",
"Q" = "Queenstown",
"S" = "Southampton")
# Take a look at the data
summary(Titanic$Departure_Point)
Cherbourg Queenstown Southampton NA's
0 168 77 644 2
LS0tDQp0aXRsZTogIioqMDUuIERhdGEgV3JhbmdsaW5nKioiDQpzdWJ0aXRsZTogIlIxMDEiDQphdXRob3I6ICJWw610IEdhYnJoZWwiDQpvdXRwdXQ6IA0KICBodG1sX25vdGVib29rOg0KICAgIHRvYzogdHJ1ZQ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