filter and select in R
dplyr's verbs for choosing rows and columns.
library(dplyr)
light <- filter(mtcars, wt < 3, mpg > 20)
either <- filter(mtcars, cyl == 4 | hp > 200)
three_cols <- select(mtcars, mpg, cyl, wt)
dropped <- select(mtcars, -disp, -drat)
by_pattern <- select(mtcars, starts_with("d"))
renamed <- rename(mtcars, miles_per_gallon = mpg)
sliced <- slice(mtcars, 1:5)
How it works
filterkeeps rows; commas mean AND,|means OR.selectkeeps or drops columns, or matches a pattern.renameandsliceadjust names and row positions.
Keywords and builtins used here
filterlibraryrenameselectslicestarts_with
The run, in numbers
- Lines
- 11
- Characters to type
- 314
- Tokens
- 88
- Three-star pace
- 95 tpm
At the three-star pace of 95 tokens a minute, this run takes about 56 seconds.
Step 5 of 5 in Rows, step 9 of 27 in dplyr.