How to do it...

Read the data from auto-mpg.csv, which includes a header row and columns separated by the default "," symbol.

  1. Read the data from auto-mpg.csv and convert cylinders to factor:
> 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")) 
  1. Get the summary statistics:
summary(auto)         No             mpg        cylinders   displacement  Min.   :  1.0   Min.   : 9.00   3cyl:  4   Min.   : 68.0  1st Qu.:100.2   1st Qu.:17.50   4cyl:204   1st Qu.:104.2  Median :199.5   Median :23.00   5cyl:  3   Median :148.5  Mean   :199.5   Mean   :23.51   6cyl: 84   Mean   :193.4  3rd Qu.:298.8   3rd Qu.:29.00   8cyl:103   3rd Qu.:262.0  Max. :398.0 ...

Get R Data Analysis Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.