Learn R Programming

iNZightTools (version 2.0.1)

filter_num: Filter data by levels of numeric variables

Description

This function filters a dataframe or survey design object by applying a specified boolean condition to one of its numeric variables. The resulting filtered dataframe is returned, along with the tidyverse code used to generate it.

Usage

filter_num(data, var, op = c("<=", "<",="" "="">=", ">", "==", "!="), num)

Value

A filtered dataframe with the tidyverse code attached.

Arguments

data

A dataframe or survey design object to be filtered.

var

The name of the column in data to be filtered by.

op

A logical operator to apply for the filtering condition. Valid options are: "<=", "<", ">=", ">", "==", or "!=".

num

The numeric value for which the specified op is applied.

Author

Owen Jin, Tom Elliott, Zhaoming Su

See Also

code

Examples

Run this code
filtered <- filter_num(iris, var = "Sepal.Length", op = "<=", num = 5)
cat(code(filtered))
head(filtered)

library(survey)
data(api)
svy <- svydesign(~ dnum + snum,
    weights = ~pw, fpc = ~ fpc1 + fpc2,
    data = apiclus2
)
svy_filtered <- filter_num(svy, var = "api00", op = "<", num = 700)
cat(code(svy_filtered))

Run the code above in your browser using DataLab