My function works fine by itself but won't work with sapply...
getFlights <- function(data, code) {
x <- data %>%
filter(origin == code ) %>%
select(origin, dest, flight) %>%
summarise(incoming = length(unique(flight)))
y<- data %>%
filter(dest == code) %>%
select(origin, dest, flight) %>%
summarise(outgoing = length(unique(flight)))
z <- cbind(x,y)
retu(z)}
When the function works by itself, it works fine! like this:
getFlights(data = bdl, code = "DFW")
But when I tried to use sapply
airports <- c("JFK", "LGA", "EWR")
sapply(airports, FUN = getFlights)
I got an error message, and the same for lapply too :
Error during wrapup: no applicable method for 'filter_' applied to an object of class "character"
