Date difference

Describe your issue

I am having trouble with adding date diff. for date of report to date onset

-# Make date-difference column %>%
mutate(diff = date_report - date_onset)

This is outcome when run:
Error in mutate():
:information_source: In argument: diff = date_report - date_onset.
Caused by error in -.Date:
! can only subtract from “Date” objects
Run rlang::last_trace() to see where the error occurred.

Follow-up

  • Thank the volunteers who try to help you
  • Mark one reply as the “Solution” if appropriate

Kia ora Ebrima,

Without a reproducible example (a reprex) it’s hard to say exactly what is causing your error, but the likely cause is that date_report is not in a date format. You can check this by using glimpse() or str() on your dataset. I recommend using one of the functions in the lubridate package if you need to convert it from a character string to a date.

Thank you gilesbgraham. You’re right, The date_report was not in date date format and was able to resolve it later. Thanks