Learn R Programming

tbltools (version 0.1.0)

filter_data: Filter rows

Description

Filter rows via integer/numeric position or logical vector

Usage

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<U+2013>users can refer to column names without quotations.

Value

Sliced/filtered data frame

Examples

Run this code
# NOT RUN {
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)

# }

Run the code above in your browser using DataLab