O'Reilly logo

R Data Analysis Cookbook by Shanthi Viswanathan, Viswa Viswanathan

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

Slicing, dicing, and combining data with data tables

R provides several packages to do data analysis and data manipulation. Over and above the apply family of functions, the most commonly used packages are plyr, reshape, dplyr, and data.table. In this recipe, we will cover data.table, which processes large amounts of data very efficiently without our having to write detailed procedural code.

Getting ready

Download the files for this chapter and store the auto-mpg.csv, employees.csv, and departments.csv files in your R working directory. Read the data and create factors for cylinders in auto-mpg.csv:

> auto <- read.csv("auto-mpg.csv", stringsAsFactors=FALSE) > auto$cylinders <- factor(auto$cylinders, levels = c(3,4,5,6,8), labels = c("3cyl", "4cyl", ...

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