This is what I was looking for
avgDelay <- function(carrier, dest)
{
TempTotal = 0
TempCount = 0
for(i in 1:dim(delays)[1])
{
if(delays$CARRIER[i] == carrier & delays$ARR_DELAY[i] >0 & is.na(delays$ARR_DELAY[i]) == FALSE & delays$DEST[i] == dest)
{
TempTotal <-TempTotal + delays$ARR_DELAY[i]
TempCount <-TempCount + 1 # keeps count of the number of delays
}
}
return(TempTotal/TempCount)
}
avgDelay("AA", "LAX")
solved Write a function that returns avg arrival delay by carrier by airport in R