1

We have flight data in the package hflights. There is one variable known as Dest (Destination Airport), I want to know how many flights are traveling to "SFO" or "OAK" destination.

This can be achieved using 3 ways :

#dataset name is hflights

library(hflights)    
flights <- tabl_df(hflights)

#1st Approach

dest_flights <- flights %>%
filter(Dest=="SFO"|Dest=="OAK")

#2nd approach 

dest_flights <- filter(flights,Dest %in% c("SFO","OAK")

#3rd approach 

dest_flights <- flights %>%

filter(Dest==c("SFO","OAK")

1st Approach and 2nd Approach will yield same results but the 3rd approach is giving different output results.

May I know what is the conceptual difference between first two and third approach ?

enter image description here

Community
  • 1
  • 1
  • Generally it's better to include context by copy and pasting text rather than linking a screenshot, but there's probably enough in the question that you don't need it anyway. – Rup May 01 '18 at 09:35
  • Why is it `Dest` instead of `dest`, remember its case sensitive. – Rana Usman May 01 '18 at 09:35
  • Apologies , the column name is "Dest" so in the code both "Dest" is same as "dest". – gourab chanda May 01 '18 at 09:52

0 Answers0