Book Image

Mastering Data analysis with R

By : Gergely Daróczi
Book Image

Mastering Data analysis with R

By: Gergely Daróczi

Overview of this book

Table of Contents (19 chapters)
Mastering Data Analysis with R
Credits
www.PacktPub.com
Preface

Drop needless data


Although not loading the needless data is the optimal solution (see the Loading a subset of text files and Loading data from databases sections in Chapter 1, Hello, Data!), we often have to filter the original dataset inside R. This can be done with the traditional tools and functions from base R, such as subset, by using which and the [ or [[ operator (see the following code), or for example with the SQL-like approach of the sqldf package:

> library(sqldf)
> sqldf("SELECT * FROM mtcars WHERE am=1 AND vs=1")
   mpg cyl  disp  hp drat    wt  qsec vs am gear carb
1 22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
2 32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1
3 30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2
4 33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1
5 27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
6 30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
7 21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2

I am sure that all readers who have...