Check correlation between age and years columns

If I have 3 columns with ages and 3 columns correlated with years, how can I verify that the difference between each age is equal to the distance between each year?
For example, in this test df all the ids are ok except 4 and 7, how can I make a code to check this in a simple way?

id age1 age2 age3 date1 date2 date3
1 17 18 19 2002 2003 2004
2 26 27 28 2019 2020 2021
3 10 10 11 2010 2010 2011
4 48 59 69 1970 1980 2000
5 30 35 40 1996 2001 2006
6 20 22 25 2012 2014 2017
7 6 16 36 2000 2010 2019

Something like

library(tidyverse)
newDF <- df |> mutate(age3_2 - age3-age2, age2_1 = age2-age1,
                      date3_2 = date3-date2, date2_1 = date2 - date1)
uhOh <- newDF |> filter( (age3_2 != date3_2) | (age2_1 != date2_1)
print(uhOh)

I think you have a typo:

newDF <- df |> mutate(age3_2 - age3-age2,

should read

newDF <- df |> mutate(age3_2 = age3-age2,

Quite right. Thanks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.