I have a column of birthdates from my participants and I need to get their ages measured in months. I'm wondering if there's an automatic way to do that accounting for facts such as that months have different number of days and years vary in number of days as well (among others) ? What I mean is: I know I can set a random 30 or 31 to months or 365 or 366 to years, but I'm wondering if is there a way to make R get the ACTUAL dates, as such Sys.Date()
does, so that I could be more precise about that. This is what I haven't seen in the other questions [EDITED]
- data:
head(data)
ID BIRTH YEAR
1 A 23/04/2009 2009
2 B 24/03/2010 2010
3 C 28/12/2009 2009
- I need to obtain participant's ages in months from a specific date. Let's say from their birth until 31/08/2020, for example (note: dates are in the Brazilian notation DAY/MONTH/YEAR). Any ideas?
I've seen many interesting posts, such as this one, but they didn't quite solve what I need, hence I hope this is not a duplicate. I've also seen some suggestions such as difftime("23/04/2009", "31/08/2020", units = 'weeks')
, but it doesn't work for months.
- data:
> dput(data)
structure(list(ID = c("A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U"
), BIRTH = c("23/04/2009", "24/03/2010", "28/12/2009", "19/08/2009",
"02/12/2009", "12/05/2010", "26/02/2010", "07/10/2009", "22/04/2010",
"01/04/2010", "31/03/2010", "27/01/2010", "23/09/2009", "28/09/2009",
"28/10/2009", "21/06/2009", "28/10/2009", "19/08/2009", "10/09/2009",
"13/07/2009", "22/09/2009"), YEAR = c("2009", "2010", "2009",
"2009", "2009", "2010", "2010", "2009", "2010", "2010", "2010",
"2010", "2009", "2009", "2009", "2009", "2009", "2009", "2009",
"2009", "2009")), row.names = c(NA, -21L), class = "data.frame")