What is the difference between (is_vacation
is a logical vector):
tapply(X = airDF[is_vacation, airDF$ArrDelay], airDF[is_vacation, airDF$FromTo], mean, na.rm = TRUE)
tapply(X = airDF[is_vacation, 'ArrDelay'], airDF[is_vacation, 'FromTo'], mean, na.rm = TRUE)
In the first option i got error:
Error in
[.data.frame
(airDF, is_vacation, airDF$FromTo) : no columns were selected.
CodePudding user response:
The first option is wrong, as instead of the column names or index, it is the column values used in the j
where as second option is fine
tapply(mtcars[1:5, 'mpg'], mtcars[1:5, 'gear'], mean)
3 4
20.05 21.60