Create a filter for a data frame, and add it to a table of filters, where each filter is represented by a row. The filter is only added if the column you specify to filter is valid.
Arguments
- filters
A data frame of filters. See filters_init.
- colname
A string specifying the column to filter.
- data
The data that is to be filtered.
Details
The function will either create a character filter or a numeric filter, depending on the type of the column. See filters_init for how these two filters work.
See also
filters_init for the filters table.
edit_filter()
andremove_filter()
to further edit the filters table.apply_filters()
to apply the filters you have created to your data.
Examples
data <- tibble::tibble(
x = 1:10,
y = "a"
)
add_filter(filters_init, "x", data)
#> # A tibble: 1 × 5
#> type colname pattern min max
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 numeric x NA 1 10
add_filter(filters_init, "y", data)
#> # A tibble: 1 × 5
#> type colname pattern min max
#> <chr> <chr> <chr> <dbl> <dbl>
#> 1 character y "" NA NA
add_filter(filters_init, "z", data)
#> # A tibble: 0 × 5
#> # … with 5 variables: type <chr>, colname <chr>, pattern <chr>, min <dbl>,
#> # max <dbl>