library("qatarcars")
str(qatarcars)
tibble [99 × 15] (S3: tbl_df/tbl/data.frame)
$ origin : Factor w/ 8 levels "Germany","Italy",..: 1 1 1 1 1 1 1 1 1 1 ...
$ make : Factor w/ 30 levels "Audi","Bentley",..: 4 4 4 1 1 1 22 22 22 22 ...
$ model : Factor w/ 99 levels "3","3 Series Convertible",..: 2 3 90 74 75 7 55 40 32 42 ...
$ length : num [1:99] 4.71 4.71 4.5 5.01 4.54 ...
..- attr(*, "label")= chr "Length (m)"
$ width : num [1:99] 1.83 1.83 1.84 1.69 1.85 ...
..- attr(*, "label")= chr "Width (m)"
$ height : num [1:99] 1.44 1.44 1.64 2 1.41 ...
..- attr(*, "label")= chr "Height (m)"
$ seating : num [1:99] 5 5 5 5 5 5 4 5 5 5 ...
..- attr(*, "label")= chr "Number of Seats"
$ trunk : num [1:99] 480 59 505 605 321 425 500 480 610 435 ...
..- attr(*, "label")= chr "Trunk Capacity (L)"
$ economy : num [1:99] 11.8 7.6 6.6 12.1 8.7 6.5 13.3 13.1 NA 5.6 ...
..- attr(*, "label")= chr "Fuel Economy (L/100km)"
$ horsepower : num [1:99] 184 386 313 600 400 180 612 585 333 163 ...
..- attr(*, "label")= chr "Horsepower"
$ price : num [1:99] 190300 164257 264000 630000 310000 ...
..- attr(*, "label")= chr "Price (QAR)"
$ mass : num [1:99] 1777 1653 1701 2490 1565 ...
..- attr(*, "label")= chr "Mass (kg)"
$ performance: num [1:99] 5.8 4.3 5.4 3.6 3.8 6.7 4.1 4.3 5.6 6.8 ...
..- attr(*, "label")= chr "Time 0-100km/h (s)"
$ type : Factor w/ 4 levels "Coupe","Hatchback",..: 1 4 3 3 4 4 4 3 4 3 ...
..- attr(*, "label")= chr "Type"
$ enginetype : Factor w/ 3 levels "Electric","Hybrid",..: 3 3 3 3 3 3 3 3 1 3 ...
..- attr(*, "label")= chr "Engine Type"
head(qatarcars)
# A tibble: 6 × 15
origin make model length width height seating trunk economy horsepower price
<fct> <fct> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 Germa… BMW 3 Se… 4.71 1.83 1.44 5 480 11.8 184 190300
2 Germa… BMW 3 Se… 4.71 1.83 1.44 5 59 7.6 386 164257
3 Germa… BMW X1 4.50 1.84 1.64 5 505 6.6 313 264000
4 Germa… Audi RS Q8 5.01 1.69 2.00 5 605 12.1 600 630000
5 Germa… Audi RS3 4.54 1.85 1.41 5 321 8.7 400 310000
6 Germa… Audi A3 4.46 1.96 1.42 5 425 6.5 180 165000
# ℹ 4 more variables: mass <dbl>, performance <dbl>, type <fct>,
# enginetype <fct>
summary(qatarcars)
origin make model length
Japan :27 Toyota :10 3 : 1 Min. :3.800
Germany :20 BMW : 5 3 Series Convertible: 1 1st Qu.:4.540
PR China :16 Kia : 5 3 Series Sedan : 1 Median :4.708
UK :11 Mercedes: 5 720S : 1 Mean :4.708
USA : 9 Lexus : 4 8 Series Gran Coupe : 1 3rd Qu.:4.881
South Korea: 8 Mazda : 4 991 Carrera S : 1 Max. :5.469
(Other) : 8 (Other) :66 (Other) :93
width height seating trunk
Min. :1.670 Min. :1.122 Min. :2.00 Min. : 0.0
1st Qu.:1.827 1st Qu.:1.452 1st Qu.:5.00 1st Qu.: 295.0
Median :1.890 Median :1.605 Median :5.00 Median : 455.0
Mean :1.926 Mean :1.581 Mean :5.04 Mean : 449.8
3rd Qu.:1.980 3rd Qu.:1.690 3rd Qu.:5.00 3rd Qu.: 550.0
Max. :4.633 Max. :1.998 Max. :8.00 Max. :1233.0
economy horsepower price mass
Min. : 1.200 Min. : 76.0 Min. : 37400 Min. : 945
1st Qu.: 6.500 1st Qu.: 166.5 1st Qu.: 101450 1st Qu.:1456
Median : 7.700 Median : 250.0 Median : 165000 Median :1751
Mean : 8.912 Mean : 329.3 Mean : 840910 Mean :1807
3rd Qu.:10.900 3rd Qu.: 384.0 3rd Qu.: 319245 3rd Qu.:2106
Max. :22.500 Max. :1973.0 Max. :33000000 Max. :2746
NA's :10
performance type enginetype
Min. : 2.400 Coupe :13 Electric:10
1st Qu.: 4.650 Hatchback: 7 Hybrid :14
Median : 6.800 SUV :49 Petrol :75
Mean : 6.813 Sedan :30
3rd Qu.: 8.400
Max. :14.000
table(qatarcars$origin)
Germany Italy Japan PR China South Korea Sweden
20 5 27 16 8 3
UK USA
11 9
aggregate(price ~ enginetype, qatarcars, mean)
enginetype price
1 Electric 1045377.0
2 Hybrid 372256.9
3 Petrol 901129.5
plot(economy ~ mass, qatarcars)
plot(price ~ performance, qatarcars, log = "y")
if (require("dplyr") && require("ggplot2")) {
glimpse(qatarcars)
qatarcars |>
count(origin)
qatarcars |>
group_by(enginetype) |>
summarize(avg_price = mean(price))
ggplot(qatarcars, aes(x = seating)) +
geom_bar()
ggplot(qatarcars, aes(x = mass, y = economy)) +
geom_point()
ggplot(qatarcars, aes(x = performance, y = price)) +
geom_point() +
scale_y_log10()
}
Rows: 99
Columns: 15
$ origin <fct> Germany, Germany, Germany, Germany, Germany, Germany, Germ…
$ make <fct> BMW, BMW, BMW, Audi, Audi, Audi, Mercedes, Mercedes, Merce…
$ model <fct> 3 Series Convertible, 3 Series Sedan, X1, RS Q8, RS3, A3, …
$ length <dbl> 4.713, 4.713, 4.505, 5.012, 4.542, 4.456, 5.469, 4.613, 5.…
$ width <dbl> 1.827, 1.827, 1.845, 1.694, 1.851, 1.960, 1.921, 1.984, 1.…
$ height <dbl> 1.440, 1.440, 1.642, 1.998, 1.412, 1.416, 1.510, 1.969, 1.…
$ seating <dbl> 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 2, 2…
$ trunk <dbl> 480, 59, 505, 605, 321, 425, 500, 480, 610, 435, 565, 132,…
$ economy <dbl> 11.8, 7.6, 6.6, 12.1, 8.7, 6.5, 13.3, 13.1, NA, 5.6, 7.5, …
$ horsepower <dbl> 184, 386, 313, 600, 400, 180, 612, 585, 333, 163, 221, 473…
$ price <dbl> 190300, 164257, 264000, 630000, 310000, 165000, 1281000, 1…
$ mass <dbl> 1777, 1653, 1701, 2490, 1565, 1325, 2376, 2588, 2495, 1565…
$ performance <dbl> 5.8, 4.3, 5.4, 3.6, 3.8, 6.7, 4.1, 4.3, 5.6, 6.8, 9.0, 3.3…
$ type <fct> Coupe, Sedan, SUV, SUV, Sedan, Sedan, Sedan, SUV, Sedan, S…
$ enginetype <fct> Petrol, Petrol, Petrol, Petrol, Petrol, Petrol, Petrol, Pe…