I'm an R beginner and am using dplyr and trying to incorporate a custom function into my R script.
I have a data frame called ss, I want to apply filters to it, but I want to separate out the filters into a separate function so it can be shared with other scripts.
Code example:
#my function
apply_filters <- function(d){
#Applying filter to d
dd <- d %>% filter([some filter])
return(dd)
}
ss2 <- ss %>%
do(apply_filters(.)) %>%
summarize()
I'm hoping to be able to send the current state of ss2 to the apply_filters function and get the resultant data back so I can summarize it.
This doesn't work as I get an error:
Error: invalid 'type' (character) of argument
Am I missing something?