I try the code from here Mean by factor by level but it does not work. Here is my situation. From the flights dataset, I want to know the average flight delay of all planes from the carrier UA.
library(nycflights13)
data(flights)
mean(flights$air_time[flights$carrier == "UA"])
But what results is just
[1] NA
What did I do wrong?