Creating standard data summaries
In this recipe we summarize the data using the summary
function.
Getting ready
If you have not already downloaded the files for this chapter, do it now and ensure that the auto-mpg.csv
file is in your R working directory.
How to do it...
Read the data from auto-mpg.csv
, which includes a header row and columns separated by the default ","
symbol.
- Read the data from
auto-mpg.csv
and convertcylinders
tofactor
:> auto <- read.csv("auto-mpg.csv", header = TRUE, stringsAsFactors = FALSE) > # Convert cylinders to factor > auto$cylinders <- factor(auto$cylinders, levels = c(3,4,5,6,8), labels = c("3cyl", "4cyl", "5cyl", "6cyl", "8cyl"))
- Get the summary statistics:
summary(auto) No mpg cylinders displacement Min. : 1.0 Min. : ...
Get R: Recipes for Analysis, Visualization and Machine Learning now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.