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

The first index in auto[1:3, 8:9] denotes the rows, and the second denotes the columns or variables. Instead of the column positions, we can also use the variable names. If using the variable names, enclose them in ....

If the required rows and columns are not contiguous, use a vector to indicate the needed rows and columns, as in auto[c(1,3), c(3,5,7)].

Use column names instead of column positions, as column positions may change in the data file.

R uses the logical operators & (and), | (or), ! (negative unary), and == (equality check).

The subset function returns all the variables (columns) if you omit the select argument. Thus, subset(auto, mpg > 30 & cylinders == 6) retrieves all the cases that match the conditions mpg ...

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