Creating New Column/Var for Diff between two Dates Var with tidyverse

Next time you visit there will be an indicator on your profile icon. Usually a beginner-to-intermediate level question attracts an answer within a day, especially if there is an appropriate reproducible minimal example attached to the question. See the FAQ: How to do a minimal reproducible example reprex for beginners.

I have the same general solution as @FJCC with two differences.

  1. I introduce the lubridate package, which is very useful for time calculations (although not needed here) and does a great job of parsing imported data to convert character strings to dates.
  2. I use the subset operator [ in place of dplyr::mutate. Again, same result through a different method. I prefer it because in conjunction with a few other base functions it covers much of what the tidyverse approach does but with less syntax. Personal preference.
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>     date, intersect, setdiff, union
DF <- data.frame(
  Date1 = ymd(c("2021-01-03", "2021-01-07", "2021-01-15")),
  Date2 = ymd(c("2021-01-05", "2021-01-15", "2021-01-01"))
DF$diffdate <- DF$Date2 - DF$Date1

#>        Date1      Date2 diffdate
#> 1 2021-01-03 2021-01-05   2 days
#> 2 2021-01-07 2021-01-15   8 days
#> 3 2021-01-15 2021-01-01 -14 days