0
votes

I have a voluminous database with several data types, e.g.:

  • A date of birth variable in format dd / mm / yyyy
  • A variable date of meeting with the subject in format dd / mm / yyyy

I have to create a new variable giving me the age of the subject in years at the time of the meeting (based on 365.25 days per year)

Each of the two variables, POSIXlt [1: 1],

format: NA to the function str ()

How can I solve this problem?

1
We can't really help here unless you tell us what the database is - a CSV file, a SQL database? Have you already read it into R? How? Can you show us the first few rows? Show us the output of summary() on your data? That would help! - Spacedman
Convert the two dates to julian. Subtract them. Then divide by 365.25 - Marichyasana

1 Answers

0
votes

Try this:

d1 = as.Date("20/11/2016", format="%d/%m/%Y")
d2 = as.Date("13/01/1995", format="%d/%m/%Y")
d3 = as.numeric(difftime(d1,d2),unit="days")
d4 = d3/365.25
print(d4)

Output: 21.85352