This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
R DATASET
# Print the mtcars data set\
mtcars
# Use the question mark to get information about the data set
?mtcars
## starting httpd help server ... done
Data_Cars <- mtcars
# Use dim() to find the dimension of the data set
dim(Data_Cars)
## [1] 32 11
# Use names() to find the names of the variables from the data set
names(Data_Cars)
## [1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear"
## [11] "carb"
Data_Cars <- mtcars
rownames(Data_Cars)
## [1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710"
## [4] "Hornet 4 Drive" "Hornet Sportabout" "Valiant"
## [7] "Duster 360" "Merc 240D" "Merc 230"
## [10] "Merc 280" "Merc 280C" "Merc 450SE"
## [13] "Merc 450SL" "Merc 450SLC" "Cadillac Fleetwood"
## [16] "Lincoln Continental" "Chrysler Imperial" "Fiat 128"
## [19] "Honda Civic" "Toyota Corolla" "Toyota Corona"
## [22] "Dodge Challenger" "AMC Javelin" "Camaro Z28"
## [25] "Pontiac Firebird" "Fiat X1-9" "Porsche 914-2"
## [28] "Lotus Europa" "Ford Pantera L" "Ferrari Dino"
## [31] "Maserati Bora" "Volvo 142E"
Data_Cars <- mtcars
Data_Cars$cyl
## [1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4
Data_Cars <- mtcars
sort(Data_Cars$cyl)
## [1] 4 4 4 4 4 4 4 4 4 4 4 6 6 6 6 6 6 6 8 8 8 8 8 8 8 8 8 8 8 8 8 8
Data_Cars <- mtcars
summary(Data_Cars)
## mpg cyl disp hp
## Min. :10.40 Min. :4.000 Min. : 71.1 Min. : 52.0
## 1st Qu.:15.43 1st Qu.:4.000 1st Qu.:120.8 1st Qu.: 96.5
## Median :19.20 Median :6.000 Median :196.3 Median :123.0
## Mean :20.09 Mean :6.188 Mean :230.7 Mean :146.7
## 3rd Qu.:22.80 3rd Qu.:8.000 3rd Qu.:326.0 3rd Qu.:180.0
## Max. :33.90 Max. :8.000 Max. :472.0 Max. :335.0
## drat wt qsec vs
## Min. :2.760 Min. :1.513 Min. :14.50 Min. :0.0000
## 1st Qu.:3.080 1st Qu.:2.581 1st Qu.:16.89 1st Qu.:0.0000
## Median :3.695 Median :3.325 Median :17.71 Median :0.0000
## Mean :3.597 Mean :3.217 Mean :17.85 Mean :0.4375
## 3rd Qu.:3.920 3rd Qu.:3.610 3rd Qu.:18.90 3rd Qu.:1.0000
## Max. :4.930 Max. :5.424 Max. :22.90 Max. :1.0000
## am gear carb
## Min. :0.0000 Min. :3.000 Min. :1.000
## 1st Qu.:0.0000 1st Qu.:3.000 1st Qu.:2.000
## Median :0.0000 Median :4.000 Median :2.000
## Mean :0.4062 Mean :3.688 Mean :2.812
## 3rd Qu.:1.0000 3rd Qu.:4.000 3rd Qu.:4.000
## Max. :1.0000 Max. :5.000 Max. :8.000
R MAX AND MIN
Data_Cars <- mtcars
max(Data_Cars$hp)
## [1] 335
min(Data_Cars$hp)
## [1] 52
Data_Cars <- mtcars
which.max(Data_Cars$hp)
## [1] 31
which.min(Data_Cars$hp)
## [1] 19
Data_Cars <- mtcars
rownames(Data_Cars)[which.max(Data_Cars$hp)]
## [1] "Maserati Bora"
rownames(Data_Cars)[which.min(Data_Cars$hp)]
## [1] "Honda Civic"
MEAN, MEDIAN, AND MODE
Data_Cars <- mtcars
mean(Data_Cars$wt)
## [1] 3.21725
Data_Cars <- mtcars
median(Data_Cars$wt)
## [1] 3.325
Data_Cars <- mtcars
names(sort(-table(Data_Cars$wt)))
## [1] "3.44" "3.57" "1.513" "1.615" "1.835" "1.935" "2.14" "2.2" "2.32"
## [10] "2.465" "2.62" "2.77" "2.78" "2.875" "3.15" "3.17" "3.19" "3.215"
## [19] "3.435" "3.46" "3.52" "3.73" "3.78" "3.84" "3.845" "4.07" "5.25"
## [28] "5.345" "5.424"
R PERCENTILES
Data_Cars <- mtcars
# c() specifies which percentile you want
quantile(Data_Cars$wt, c(0.75))
## 75%
## 3.61
Data_Cars <- mtcars
quantile(Data_Cars$wt)
## 0% 25% 50% 75% 100%
## 1.51300 2.58125 3.32500 3.61000 5.42400