O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required