filter_data: Filter rows

Description Usage Arguments Value Examples

View source: R/filter.R

Description

Filter rows via integer/numeric position or logical vector

Usage

1
filter_data(.data, ...)

Arguments

.data

Data frame or two dimensional array

...

Each argument/expression should should evaluate and reduce down to an integer (row number) or logical vector. The filter will keep all row numbers that appear in all evaluated expressions (commas are the equivalent to &. Row numbers higher than what exists in x will be ignored. Any numeric vector must be either all positive or all negative (excludes). This function uses non-standard evaluation–users can refer to column names without quotations.

Value

Sliced/filtered data frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
set.seed(12)
d <- data.frame(
  mpg = rnorm(100, 25, 3),
  gear = sample(3:6, 100, replace = TRUE),
  vs = sample(0:1, 100, replace = TRUE),
  stringsAsFactors = FALSE
)

filter_data(d, mpg > 30)
filter_data(d, !mpg < 30)
filter_data(d, mpg > 30, !mpg < 30)
filter_data(d, mpg > 30, gear == 4)
filter_data(d, mpg > 30 | gear == 4, vs == 1)

tbltools documentation built on Feb. 9, 2019, 1:04 a.m.