Using the 1990 airport data, we can find the average departure delay for flights from each airport.
library(data.table)
myDF <- fread("/anvil/projects/tdm/data/flights/subset/1990.csv")
There are many columns in this data set:
head(myDF)
Likely, you were not able to see all of the columns on the screen, in your Jupyter Lab session. We can tell Jupyter Lab to show all of the columns in this way:
options(repr.matrix.max.cols = Inf)
head(myDF)
We take the departure delays (in the DepDelay column), group the data according to airport where the flights depart (in the Origin column), and take an average of these departure delays:
tapply(myDF$DepDelay, myDF$Origin, mean)
The values show up as "NA" (not available) because some values are missing, so R cannot take an average. In such a case, we can give R the fourth parameter na.rm=TRUE so that it ignores missing values, and we try again:
tapply(myDF$DepDelay, myDF$Origin, mean, na.rm=TRUE)