Solutions

(1) We use is.na inside table.

table(is.na(nyc_taxi$pickup_longitude))
  FALSE    TRUE 
3785897   66465

(2) We can combine both statements using &.

table(is.na(nyc_taxi$pickup_longitude) & is.na(nyc_taxi$pickup_latitude))
  FALSE    TRUE 
3785913   66449

We can also separate the two statements and pass them as separate arguments to table. Doing so gives us a two-way table with a little more information.

table(is.na(nyc_taxi$pickup_longitude), is.na(nyc_taxi$pickup_latitude)) # better solution to (2)
          FALSE    TRUE
  FALSE 3785730     167
  TRUE       16   66449

(3) Providing n arguments to table gives us an n-way table, which is an array object. When n > 3 it gets confusing to look at it, so here we can use & to simplify things.

with(nyc_taxi,
     table(is.na(pickup_longitude) & is.na(pickup_latitude),
           is.na(dropoff_longitude) & is.na(dropoff_latitude))
)
          FALSE    TRUE
  FALSE 3779332    6581
  TRUE     8659   57790

results matching ""

    No results matching ""