socar <- read.csv(file = 'Socar Data.csv')
socar
## Renter_ID First_Name Second_Name Age Car_Model Reservation_Date Days Price
## 1 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## 2 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## 3 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## 4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## 5 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## 6 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## 7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
Renter_ID = c(30120, 20185, 17852, 44325, 23596, 38193, 61407)
First_Name = c("Rahil", "Hoon", "How", "Terry", "Jaclyn", "Kousalya", "Nur")
Second_Name = c("Ahmed", "Seo", "Wee Lee", "Kuan", "Lim", "Manju", "Hidayah")
Age = c(27, 38, 26, 26, 24, 31, 47)
Car_Model = c("Axia", "Passat", "BMW", "Myvi", "Vellfire", "Mini Cooper", "Ford Ranger")
Reservation_Date = c("2020-10-06", "2020-09-21", "2020-04-03", "2020-07-16", "2020-02-29", "2020-11-05", "2020-01-08")
Days = c(3.0, 2.5, 1.0, 12.0, 1.0, 4.5, 6.5)
Price = c(210.0, 1231.0, 598.8, 900.0, 429.3, 1994.4, 3432.0)
socar1 <- data.frame(Renter_ID, First_Name, Second_Name, Age, Car_Model, Reservation_Date, Days, Price, stringsAsFactors = FALSE)
socar1
## Renter_ID First_Name Second_Name Age Car_Model Reservation_Date Days Price
## 1 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## 2 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## 3 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## 4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## 5 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## 6 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## 7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
socar$Name <- paste(socar$First_Name, socar$Second_Name)
socar
## Renter_ID First_Name Second_Name Age Car_Model Reservation_Date Days Price
## 1 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## 2 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## 3 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## 4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## 5 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## 6 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## 7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
## Name
## 1 Rahil Ahmed
## 2 Hoon Seo
## 3 How Wee Lee
## 4 Terry Kuan
## 5 Jaclyn Lim
## 6 Kousalya Manju
## 7 Nur Hidayah
socar <- socar[,c(-2,-3)]
socar
## Renter_ID Age Car_Model Reservation_Date Days Price Name
## 1 30120 27 Axia 2020-10-06 3.0 210.0 Rahil Ahmed
## 2 20185 38 Passat 2020-09-21 2.5 1231.0 Hoon Seo
## 3 17852 26 BMW 2020-04-03 1.0 598.8 How Wee Lee
## 4 44325 26 Myvi 2020-07-16 12.0 900.0 Terry Kuan
## 5 23596 24 Vellfire 2020-02-29 1.0 429.3 Jaclyn Lim
## 6 38193 31 Mini Cooper 2020-11-05 4.5 1994.4 Kousalya Manju
## 7 61407 47 Ford Ranger 2020-01-08 6.5 3432.0 Nur Hidayah
socar <- socar[,c(1,7,2,3,4,5,6)]
socar
## Renter_ID Name Age Car_Model Reservation_Date Days Price
## 1 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## 2 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## 3 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## 4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## 5 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## 6 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## 7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
date
and data type “Renter_ID” to character
using explicit coercion.socar$Reservation_Date <- as.Date(socar$Reservation_Date, "%Y-%m-%d")
socar$Renter_ID <- as.character(socar$Renter_ID)
socar
## Renter_ID Name Age Car_Model Reservation_Date Days Price
## 1 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## 2 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## 3 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## 4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## 5 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## 6 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## 7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
socar <- socar[order(Reservation_Date, decreasing=TRUE),]
socar
## Renter_ID Name Age Car_Model Reservation_Date Days Price
## 6 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## 1 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## 2 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## 4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## 3 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## 5 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## 7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
is.data.frame(socar)
## [1] TRUE
str(socar)
## 'data.frame': 7 obs. of 7 variables:
## $ Renter_ID : chr "38193" "30120" "20185" "44325" ...
## $ Name : chr "Kousalya Manju" "Rahil Ahmed" "Hoon Seo" "Terry Kuan" ...
## $ Age : int 31 27 38 26 26 24 47
## $ Car_Model : chr "Mini Cooper" "Axia" "Passat" "Myvi" ...
## $ Reservation_Date: Date, format: "2020-11-05" "2020-10-06" ...
## $ Days : num 4.5 3 2.5 12 1 1 6.5
## $ Price : num 1994 210 1231 900 599 ...
summary(socar)
## Renter_ID Name Age Car_Model
## Length:7 Length:7 Min. :24.00 Length:7
## Class :character Class :character 1st Qu.:26.00 Class :character
## Mode :character Mode :character Median :27.00 Mode :character
## Mean :31.29
## 3rd Qu.:34.50
## Max. :47.00
## Reservation_Date Days Price
## Min. :2020-01-08 Min. : 1.000 Min. : 210
## 1st Qu.:2020-03-17 1st Qu.: 1.750 1st Qu.: 514
## Median :2020-07-16 Median : 3.000 Median : 900
## Mean :2020-06-21 Mean : 4.357 Mean :1256
## 3rd Qu.:2020-09-28 3rd Qu.: 5.500 3rd Qu.:1613
## Max. :2020-11-05 Max. :12.000 Max. :3432
kableExtra
and utilize function kable
to view data frames in a more readable, tabular format.library(kableExtra)
knitr::kable(socar[, 1:7], "simple", align = "clclcrr", bootstrap_options = "striped", font_size = 10, full_width= F, caption = "Table 1: Socar Data.")
Renter_ID | Name | Age | Car_Model | Reservation_Date | Days | Price | |
---|---|---|---|---|---|---|---|
6 | 38193 | Kousalya Manju | 31 | Mini Cooper | 2020-11-05 | 4.5 | 1994.4 |
1 | 30120 | Rahil Ahmed | 27 | Axia | 2020-10-06 | 3.0 | 210.0 |
2 | 20185 | Hoon Seo | 38 | Passat | 2020-09-21 | 2.5 | 1231.0 |
4 | 44325 | Terry Kuan | 26 | Myvi | 2020-07-16 | 12.0 | 900.0 |
3 | 17852 | How Wee Lee | 26 | BMW | 2020-04-03 | 1.0 | 598.8 |
5 | 23596 | Jaclyn Lim | 24 | Vellfire | 2020-02-29 | 1.0 | 429.3 |
7 | 61407 | Nur Hidayah | 47 | Ford Ranger | 2020-01-08 | 6.5 | 3432.0 |
socar
## Renter_ID Name Age Car_Model Reservation_Date Days Price
## 6 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## 1 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## 2 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## 4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## 3 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## 5 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## 7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
ncol(socar)
## [1] 7
nrow(socar)
## [1] 7
length(socar)
## [1] 7
names(socar)
## [1] "Renter_ID" "Name" "Age" "Car_Model"
## [5] "Reservation_Date" "Days" "Price"
row.names(socar)
## [1] "6" "1" "2" "4" "3" "5" "7"
names(socar)[names(socar) == 'Renter_ID'] <- 'ID'
socar
## ID Name Age Car_Model Reservation_Date Days Price
## 6 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## 1 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## 2 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## 4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## 3 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## 5 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## 7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
names(socar) <- c("ID","Name", "Age", "Car Model", "Booking Date", "Days", "Price")
socar
## ID Name Age Car Model Booking Date Days Price
## 6 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## 1 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## 2 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## 4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## 3 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## 5 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## 7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
row.names(socar) <- c("S1", "S2", "S3", "S4", "S5", "S6", "S7")
socar
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## S3 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## S7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
socar
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## S3 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## S7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
socar["Age"]
## Age
## S1 31
## S2 27
## S3 38
## S4 26
## S5 26
## S6 24
## S7 47
class(socar["Age"])
## [1] "data.frame"
$
operator.socar$Age
## [1] 31 27 38 26 26 24 47
[[ ]]
operator with column name.socar[["Age"]]
## [1] 31 27 38 26 26 24 47
[[ ]]
operator with column index number.socar[[3]]
## [1] 31 27 38 26 26 24 47
class(socar[["Age"]])
## [1] "integer"
socar["S1",]
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
$
operator.socar$Age[3]
## [1] 38
[[ ]]
operator with column name.socar[["Age"]][3]
## [1] 38
[[ ]]
operator with column index number.socar[[3]][3]
## [1] 38
socar[5,]
## ID Name Age Car Model Booking Date Days Price
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1 598.8
class(socar[5,])
## [1] "data.frame"
typeof(socar[5,])
## [1] "list"
socar[,4]
## [1] "Mini Cooper" "Axia" "Passat" "Myvi" "BMW"
## [6] "Vellfire" "Ford Ranger"
class(socar[,4])
## [1] "character"
socar[,4, drop = FALSE]
## Car Model
## S1 Mini Cooper
## S2 Axia
## S3 Passat
## S4 Myvi
## S5 BMW
## S6 Vellfire
## S7 Ford Ranger
class(socar[,4, drop = FALSE])
## [1] "data.frame"
socar[5,4]
## [1] "BMW"
socar
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## S3 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## S7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
socar[c(1,5),]
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
socar[c(-3, -6),]
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
socar[c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE),]
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S3 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
socar[,c("Car Model", "Price")]
## Car Model Price
## S1 Mini Cooper 1994.4
## S2 Axia 210.0
## S3 Passat 1231.0
## S4 Myvi 900.0
## S5 BMW 598.8
## S6 Vellfire 429.3
## S7 Ford Ranger 3432.0
socar[c("S1", "S4"), 3:5]
## Age Car Model Booking Date
## S1 31 Mini Cooper 2020-11-05
## S4 26 Myvi 2020-07-16
$Na
is similar to $Name
socar$Na
## [1] "Kousalya Manju" "Rahil Ahmed" "Hoon Seo" "Terry Kuan"
## [5] "How Wee Lee" "Jaclyn Lim" "Nur Hidayah"
head(socar)
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## S3 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
tail(socar, 4)
## ID Name Age Car Model Booking Date Days Price
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## S7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
Renters aged 26.
socar[socar$Age == 26,]
## ID Name Age Car Model Booking Date Days Price
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12 900.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1 598.8
Renters aged 26.
subset(socar, Age == 26)
## ID Name Age Car Model Booking Date Days Price
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12 900.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1 598.8
Renters who booked a Passat or cars worth more than RM1000.
socar[socar$"Car Model" == "Passat" | socar$Price > 1000,]
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S3 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## S7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
Renters who are below 30 years old and booked a car before 30th June 2020.
socar[socar$Age < 30 & socar$"Booking Date" < "2020-06-30",]
## ID Name Age Car Model Booking Date Days Price
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1 429.3
socar
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## S3 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 900.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## S7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
Changing Terry Kuan’s expenditure from RM900 to RM1200.
socar[4,"Price"] <- 1200
socar
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 31 Mini Cooper 2020-11-05 4.5 1994.4
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## S3 20185 Hoon Seo 38 Passat 2020-09-21 2.5 1231.0
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 1200.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## S7 61407 Nur Hidayah 47 Ford Ranger 2020-01-08 6.5 3432.0
Replacing all renters above age 30 to an age value of 40.
socar[socar$"Age" > 30, 3] <- 40
socar
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 40 Mini Cooper 2020-11-05 4.5 1994.4
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## S3 20185 Hoon Seo 40 Passat 2020-09-21 2.5 1231.0
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 1200.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## S7 61407 Nur Hidayah 40 Ford Ranger 2020-01-08 6.5 3432.0
socar <- rbind(socar, list(70426, "Aniq Kaw", 25, "Bezza", "2020-11-11", 3, 240))
socar
## ID Name Age Car Model Booking Date Days Price
## S1 38193 Kousalya Manju 40 Mini Cooper 2020-11-05 4.5 1994.4
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0
## S3 20185 Hoon Seo 40 Passat 2020-09-21 2.5 1231.0
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 1200.0
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3
## S7 61407 Nur Hidayah 40 Ford Ranger 2020-01-08 6.5 3432.0
## 8 70426 Aniq Kaw 25 Bezza 2020-11-11 3.0 240.0
socar <- cbind(socar, Country = c("MY", "IN", "KR", "CN", "US", "HK", "MY", "UK"))
socar
## ID Name Age Car Model Booking Date Days Price Country
## S1 38193 Kousalya Manju 40 Mini Cooper 2020-11-05 4.5 1994.4 MY
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0 IN
## S3 20185 Hoon Seo 40 Passat 2020-09-21 2.5 1231.0 KR
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 1200.0 CN
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8 US
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3 HK
## S7 61407 Nur Hidayah 40 Ford Ranger 2020-01-08 6.5 3432.0 MY
## 8 70426 Aniq Kaw 25 Bezza 2020-11-11 3.0 240.0 UK
$
operator: Add a new column, “Gender” with data type, factor
. Factors are usually used to represent categorical data.socar$Gender <- factor(c("F", "M", "M", "M", "M", "F", "F", "M"), levels = c("M", "F", "Not sure"))
socar
## ID Name Age Car Model Booking Date Days Price Country Gender
## S1 38193 Kousalya Manju 40 Mini Cooper 2020-11-05 4.5 1994.4 MY F
## S2 30120 Rahil Ahmed 27 Axia 2020-10-06 3.0 210.0 IN M
## S3 20185 Hoon Seo 40 Passat 2020-09-21 2.5 1231.0 KR M
## S4 44325 Terry Kuan 26 Myvi 2020-07-16 12.0 1200.0 CN M
## S5 17852 How Wee Lee 26 BMW 2020-04-03 1.0 598.8 US M
## S6 23596 Jaclyn Lim 24 Vellfire 2020-02-29 1.0 429.3 HK F
## S7 61407 Nur Hidayah 40 Ford Ranger 2020-01-08 6.5 3432.0 MY F
## 8 70426 Aniq Kaw 25 Bezza 2020-11-11 3.0 240.0 UK M
class(socar$Gender)
## [1] "factor"
$
operator for columns.socar$ID <- NULL
socar$Age <- NULL
socar
## Name Car Model Booking Date Days Price Country Gender
## S1 Kousalya Manju Mini Cooper 2020-11-05 4.5 1994.4 MY F
## S2 Rahil Ahmed Axia 2020-10-06 3.0 210.0 IN M
## S3 Hoon Seo Passat 2020-09-21 2.5 1231.0 KR M
## S4 Terry Kuan Myvi 2020-07-16 12.0 1200.0 CN M
## S5 How Wee Lee BMW 2020-04-03 1.0 598.8 US M
## S6 Jaclyn Lim Vellfire 2020-02-29 1.0 429.3 HK F
## S7 Nur Hidayah Ford Ranger 2020-01-08 6.5 3432.0 MY F
## 8 Aniq Kaw Bezza 2020-11-11 3.0 240.0 UK M
socar <- socar[-4,]
socar
## Name Car Model Booking Date Days Price Country Gender
## S1 Kousalya Manju Mini Cooper 2020-11-05 4.5 1994.4 MY F
## S2 Rahil Ahmed Axia 2020-10-06 3.0 210.0 IN M
## S3 Hoon Seo Passat 2020-09-21 2.5 1231.0 KR M
## S5 How Wee Lee BMW 2020-04-03 1.0 598.8 US M
## S6 Jaclyn Lim Vellfire 2020-02-29 1.0 429.3 HK F
## S7 Nur Hidayah Ford Ranger 2020-01-08 6.5 3432.0 MY F
## 8 Aniq Kaw Bezza 2020-11-11 3.0 240.0 UK M
Extra charges causing price to increase by RM100.
socar["Price"] + 100
## Price
## S1 2094.4
## S2 310.0
## S3 1331.0
## S5 698.8
## S6 529.3
## S7 3532.0
## 8 340.0
Find price per day (PPD) for each renter.
socar <- transform(socar, PPD = Price / Days)
socar
## Name Car.Model Booking.Date Days Price Country Gender PPD
## S1 Kousalya Manju Mini Cooper 2020-11-05 4.5 1994.4 MY F 443.2
## S2 Rahil Ahmed Axia 2020-10-06 3.0 210.0 IN M 70.0
## S3 Hoon Seo Passat 2020-09-21 2.5 1231.0 KR M 492.4
## S5 How Wee Lee BMW 2020-04-03 1.0 598.8 US M 598.8
## S6 Jaclyn Lim Vellfire 2020-02-29 1.0 429.3 HK F 429.3
## S7 Nur Hidayah Ford Ranger 2020-01-08 6.5 3432.0 MY F 528.0
## 8 Aniq Kaw Bezza 2020-11-11 3.0 240.0 UK M 80.0
unique(socar$Gender)
## [1] F M
## Levels: M F Not sure
t(socar)
## S1 S2 S3 S5
## Name "Kousalya Manju" "Rahil Ahmed" "Hoon Seo" "How Wee Lee"
## Car.Model "Mini Cooper" "Axia" "Passat" "BMW"
## Booking.Date "2020-11-05" "2020-10-06" "2020-09-21" "2020-04-03"
## Days "4.5" "3.0" "2.5" "1.0"
## Price "1994.4" " 210.0" "1231.0" " 598.8"
## Country "MY" "IN" "KR" "US"
## Gender "F" "M" "M" "M"
## PPD "443.2" " 70.0" "492.4" "598.8"
## S6 S7 8
## Name "Jaclyn Lim" "Nur Hidayah" "Aniq Kaw"
## Car.Model "Vellfire" "Ford Ranger" "Bezza"
## Booking.Date "2020-02-29" "2020-01-08" "2020-11-11"
## Days "1.0" "6.5" "3.0"
## Price " 429.3" "3432.0" " 240.0"
## Country "HK" "MY" "UK"
## Gender "F" "F" "M"
## PPD "429.3" "528.0" " 80.0"
as.list(socar)
## $Name
## [1] "Kousalya Manju" "Rahil Ahmed" "Hoon Seo" "How Wee Lee"
## [5] "Jaclyn Lim" "Nur Hidayah" "Aniq Kaw"
##
## $Car.Model
## [1] "Mini Cooper" "Axia" "Passat" "BMW" "Vellfire"
## [6] "Ford Ranger" "Bezza"
##
## $Booking.Date
## [1] "2020-11-05" "2020-10-06" "2020-09-21" "2020-04-03" "2020-02-29"
## [6] "2020-01-08" "2020-11-11"
##
## $Days
## [1] 4.5 3.0 2.5 1.0 1.0 6.5 3.0
##
## $Price
## [1] 1994.4 210.0 1231.0 598.8 429.3 3432.0 240.0
##
## $Country
## [1] "MY" "IN" "KR" "US" "HK" "MY" "UK"
##
## $Gender
## [1] F M M M F F M
## Levels: M F Not sure
##
## $PPD
## [1] 443.2 70.0 492.4 598.8 429.3 528.0 80.0
library("jsonlite")
cat(toJSON(socar))
## [{"Name":"Kousalya Manju","Car.Model":"Mini Cooper","Booking.Date":"2020-11-05","Days":4.5,"Price":1994.4,"Country":"MY","Gender":"F","PPD":443.2,"_row":"S1"},{"Name":"Rahil Ahmed","Car.Model":"Axia","Booking.Date":"2020-10-06","Days":3,"Price":210,"Country":"IN","Gender":"M","PPD":70,"_row":"S2"},{"Name":"Hoon Seo","Car.Model":"Passat","Booking.Date":"2020-09-21","Days":2.5,"Price":1231,"Country":"KR","Gender":"M","PPD":492.4,"_row":"S3"},{"Name":"How Wee Lee","Car.Model":"BMW","Booking.Date":"2020-04-03","Days":1,"Price":598.8,"Country":"US","Gender":"M","PPD":598.8,"_row":"S5"},{"Name":"Jaclyn Lim","Car.Model":"Vellfire","Booking.Date":"2020-02-29","Days":1,"Price":429.3,"Country":"HK","Gender":"F","PPD":429.3,"_row":"S6"},{"Name":"Nur Hidayah","Car.Model":"Ford Ranger","Booking.Date":"2020-01-08","Days":6.5,"Price":3432,"Country":"MY","Gender":"F","PPD":528,"_row":"S7"},{"Name":"Aniq Kaw","Car.Model":"Bezza","Booking.Date":"2020-11-11","Days":3,"Price":240,"Country":"UK","Gender":"M","PPD":80,"_row":"8"}]