filter_by_sub | R Documentation |
Applies filter
to rows in a data frame based on the results of that row's nested data frame. Each logical predicate supplied to ... must evaluate to a logical of length 1, similar to summarise
(which this function calls).
filter_by_sub(df, data_col_name, ..., handle_nulls = FALSE)
df |
A data frame / tibble |
data_col_name |
The column name of the nested data frames, bare or as a string. |
... |
Logical predicates defined in terms of the variables in |
handle_nulls |
If |
drop_empty |
If |
Unlike filter_in_sub
, which applies a filter within the nested data frames, filter_by_sub
applies the filter to the top-level data frame.
A data frame / tibble
filter_in_sub
d <- mtcars %>% dplyr::mutate(Name=row.names(mtcars)) %>% as_tibble() %>% tidyr::nest(-cyl) d %>% filter_by_sub(data, any(grepl("Merc", Name)), n() > 12) # We can see what happens when we make a nested data frame NULL and if we make it a row of 0 d[2,]$data <- list(NULL) d[1,]$data <- list(d[1,]$data[[1]][FALSE,]) d ## Not run: d %>% filter_by_sub(data, any(grepl("Merc", Name)), all(mpg < 20)) ## End(Not run) d %>% filter_by_sub(data, any(grepl("Merc", Name)), all(mpg < 20), handle_nulls = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.