Filter data with user-specified expression

filter_data(dataset, filt = "", drop = TRUE)

Arguments

dataset

Data frame to filter

filt

Filter expression to apply to the specified dataset

drop

Drop unused factor levels after filtering (default is TRUE)

Value

Filtered data frame

Details

Filters can be used to view a sample from a selected dataset. For example, runif(nrow(.)) > .9 could be used to sample approximately 10

Examples

select(diamonds, 1:3) %>% filter_data(filt = "price > max(.$price) - 100")
#> # A tibble: 2 x 3 #> price carat clarity #> <int> <dbl> <fct> #> 1 18791 2.15 SI2 #> 2 18745 2.36 SI2
select(diamonds, 1:3) %>% filter_data(filt = "runif(nrow(.)) > .995")
#> # A tibble: 17 x 3 #> price carat clarity #> <int> <dbl> <fct> #> 1 650 0.34 SI1 #> 2 743 0.33 SI1 #> 3 3774 0.83 VVS1 #> 4 1214 0.5 SI1 #> 5 589 0.32 SI1 #> 6 989 0.41 VS1 #> 7 2715 0.8 SI2 #> 8 11826 1.51 VVS2 #> 9 2407 0.7 SI1 #> 10 974 0.46 VVS1 #> 11 969 0.41 SI1 #> 12 13827 2.24 SI2 #> 13 2096 0.54 IF #> 14 4375 1.04 SI2 #> 15 911 0.3 VS2 #> 16 1320 0.55 SI1 #> 17 687 0.31 VVS1