1

Executing

filter(i -> !ismissing(i.dep_delay > 60), select(flights, (:carrier, :dep_delay)))

should return the carriers with delay more than 60mins(my understanding!). But it returns carriers with all positive and negative dep_delays.

Why it behaves so?

AVA
  • 2,474
  • 2
  • 26
  • 41

1 Answers1

1

I understand you rather wanted to write:

filter(i -> coalesce(i.dep_delay > 60, false), select(flights, (:carrier, :dep_delay)))

If you write !ismissing(i.dep_delay > 60) you will get true if i.dep_delay is not missing.

Bogumił Kamiński
  • 66,844
  • 3
  • 80
  • 107
  • sir, a short note on functionality of coalesce(), please! – AVA May 22 '19 at 06:05
  • 1
    It is a standard function in Base. If you look up its help you get: return the first value in the arguments which is not equal to `missing`, if any. Otherwise return `missing`. In a typical application (like the one you have) it is used to replace a `missing` with some value. So essentially `coalesce(v, v2)` is the same as `ismissing(v) ? v2 : v`. The difference is that `coalesce` can accept any number of arguments, but two-argument form is the most common. – Bogumił Kamiński May 22 '19 at 06:13