Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to write this if else statement in R?

Does anyone know how to write an if else statement in R where if the departure delay is more than 15 minutes then the airline has to pay $75 for every minute delayed and if the departure delay is less than 15 minutes then there is no charge?

This is what I wrote but its throwing an error

mutate(Departure Delay charges= if_else(departure_delay>= ’16’|DEP_DELAY<=’15’,75*departure_delay, "0" ))

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you need > 15 mins, then the second dep_delay is not necessary. If true it will multiply departure_delay by 75, it it is FALSE – it will stay 0.

DepartureDelayCharges = ifelse(departure_delay >= 16, 75*departure_delay, 0)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading