Solutions

(1) We can pass the two columns (vectors) directly to all.equal to check if they are the same, but the second column needs to be computed on the fly.

with(nyc_taxi,
     all.equal(total_amount, 
               fare_amount + extra + mta_tax + tip_amount + tolls_amount + improvement_surcharge)
)

(2) Another way to check for equality is by looking at correlation. Two identical columns of numeric type will have a correlation of 1.

with(nyc_taxi,
     cor(total_amount, # we could use correlation instead of `all.equal`
         fare_amount + extra + mta_tax + tip_amount + tolls_amount + improvement_surcharge)
)

results matching ""

    No results matching ""