I'm trying to create a function that captures the amplitude of flight arrivals and departures. but getting this error: "non-numeric argument to binary operato". even though through the command class I discovered that arr and dep are numeric. I'm using nyclights13 data. Can you guys help?
I'd like to take a stab at helping you out here, but let me know if I misunderstand your function fmp2.
What I believe is throwing the non-numeric to binary operator error is the presence of "deptime_delay:" and the other strings in the max() and min() functions. Now I could be wrong with that but I think those functions are only capable of handling numerics. I'm not sure what your goal is with those strings, whether you're looking to label your result or specify a column of data.
Here is a version of your code, minus the strings in the max and min functions:
# two example lists of numeric values to use
test_list_1 <- c(1, 2, 3, 4, 65)
test_list_2 <- c(12, 20, 100, 10, 9)
# version of your function that removes the character strings
test_fxn <- function(x, y) {
testResult <- max(x, y) - min(x, y)
return(testResult)
}
# running map2 over the lists with the test function
map2(test_list_1, test_list_2, test_fxn)