How To Load Mpg Data In R
The mtcars dataset is a built-in dataset in R that contains measurements on xi different attributes for 32 unlike cars.
This tutorial explains how to explore, summarize, and visualize the mtcars dataset in R.
Related: A Consummate Guide to the Iris Dataset in R
Load the mtcars Dataset
Since the mtcars dataset is a built-in dataset in R, we can load it past using the post-obit command:
information(mtcars)
Nosotros tin can take a await at the offset half dozen rows of the dataset by using the head() function:
#view first six rows of mtcars dataset head(mtcars) mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 six 160 110 3.xc 2.620 sixteen.46 0 i 4 4 Mazda RX4 Wag 21.0 half dozen 160 110 3.90 2.875 17.02 0 1 four iv Datsun 710 22.8 iv 108 93 iii.85 ii.320 18.61 1 1 4 i Hornet 4 Drive 21.four vi 258 110 3.08 three.215 nineteen.44 ane 0 3 1 Hornet Sportabout 18.7 eight 360 175 3.15 3.440 17.02 0 0 iii 2 Valiant 18.ane 6 225 105 2.76 three.460 20.22 i 0 3 one
Summarize the mtcars Dataset
Nosotros can use the summary() office to quickly summarize each variable in the dataset:
#summarize mtcars dataset summary(mtcars) mpg cyl disp hp Min. :ten.40 Min. :4.000 Min. : 71.1 Min. : 52.0 1st Qu.:fifteen.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.seven Mean :146.7 3rd Qu.:22.80 3rd Qu.:eight.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.fifty Min. :0.0000 1st Qu.:3.080 1st Qu.:2.581 1st Qu.:xvi.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 Hateful :0.4375 3rd Qu.:three.920 3rd Qu.:3.610 3rd Qu.:xviii.90 tertiary Qu.:one.0000 Max. :4.930 Max. :v.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 :iv.000 Median :2.000 Hateful :0.4062 Mean :3.688 Mean :2.812 3rd Qu.:1.0000 3rd Qu.:4.000 3rd Qu.:iv.000 Max. :1.0000 Max. :5.000 Max. :8.000
For each of the 11 variables nosotros tin see the following information:
- Min: The minimum value.
- 1st Qu: The value of the first quartile (25th percentile).
- Median: The median value.
- Mean: The mean value.
- 3rd Qu: The value of the third quartile (75th percentile).
- Max: The maximum value.
We tin can use the dim() function to get the dimensions of the dataset in terms of number of rows and number of columns:
#display rows and columns dim(mtcars) [1] 32 xi
We can meet that the dataset has 32 rows and 11 columns.
We tin can also use the names() office to display the column names of the data frame:
#display column names names(mtcars) [ane] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear" [11] "carb"
Visualize the mtcars Dataset
We tin can also create some plots to visualize the values in the dataset.
For instance, we can use the hist() office to create a histogram of the values for a sure variable:
#create histogram of values for mpg hist(mtcars$mpg, col='steelblue', main='Histogram', xlab='mpg', ylab='Frequency')
Nosotros could likewise use the boxplot() function to create a boxplot to visualize the distribution of values for a certain variable:
#create boxplot of values for mpg boxplot(mtcars$mpg, main=' Distribution of mpg values ', ylab=' mpg ', col=' steelblue ', edge=' black ')
We can also use the plot() function to create a scatterplot of any pairwise combination of variables:
#create scatterplot of mpg vs. wt plot(mtcars$mpg, mtcars$wt, col='steelblue', chief='Scatterplot', xlab='mpg', ylab='wt', pch=19)
By using these built-in functions in R, we tin can learn a not bad deal about the mtcars dataset.
If yous'd like to perform more advanced statistical analysis with this dataset, cheque out this tutorial that explains how to fit linear regression models and generalized linear models using the mtcars dataset.
Additional Resources
The post-obit tutorials explain how to perform other mutual tasks in R:
The Easiest Style to Create Summary Tables in R
How to Calculate 5 Number Summary in R
How to Perform Simple Linear Regression in R
How To Load Mpg Data In R,
Source: https://www.statology.org/mtcars-dataset-r/
Posted by: ellislaut2000.blogspot.com
0 Response to "How To Load Mpg Data In R"
Post a Comment