Selecting rows
To select rows from a dataframe use the filter()
function (again from
dplyr
).
If we only wanted to rows for 6-cylindered cars, we could write:
filter(mtcars, cyl==6)
mpg cyl disp hp drat wt qsec vs am gear carb
1 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
2 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
3 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
4 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1
5 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4
6 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4
7 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6