change a column from birth date to age in r

monkeyshines

I am using data.table for the first time.

I have a column of about 400,000 ages in my table. I need to convert them from birth dates to ages.

What is the best way to do this?

Gregor Thomas

From the comments of this blog entry, I found the age_calc function in the eeptools package. It takes care of edge cases (leap years, etc.), checks inputs and looks quite robust.

library(eeptools)
x <- as.Date(c("2011-01-01", "1996-02-29"))
age_calc(x[1],x[2]) # default is age in months

[1] 46.73333 224.83118

age_calc(x[1],x[2], units = "years") # but you can set it to years

[1] 3.893151 18.731507

floor(age_calc(x[1],x[2], units = "years"))

[1] 3 18

For your data

yourdata$age <- floor(age_calc(yourdata$birthdate, units = "years"))

assuming you want age in integer years.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Calculate age based on date of birth

From Dev

Calculate age with decimals from date of birth

From Dev

Calculate the age using the date of birth

From Dev

MySQL Age from Date of Birth (ignore nulls)

From Dev

Calculating age with current date and birth date in Java

From Dev

Calucate age from birth date in mysql

From Dev

How to calculate age from date of birth and group each member into age range in sql

From Dev

Calculate age from birth date using NSDateComponents in Swift

From Dev

Finding date of birth from age in java

From Dev

Pandas get the age from a date (example: date of birth)

From Dev

Finding age with date of birth and grouping in terms of age in R

From Dev

Calculate age from birth date

From Dev

Validating Age from the Date of Birth

From Dev

Efficient and accurate age calculation (in years, months, or weeks) in R given birth date and an arbitrary date

From Dev

Algolia instantsearch age rangeslider base on date of birth

From Dev

SQL. Convert age to date of birth

From Dev

search for users age based on date of birth

From Dev

Calculate age based on date of birth

From Dev

Calculate the age using the date of birth

From Dev

SQL Server calculating age from varchar date of birth

From Dev

Javascript to calculate a fictional date of birth from todays date and fixed age

From Dev

Basic age validation from date of birth in PHP

From Dev

Age extracted from birth date always off by inconsistent amount

From Dev

How to calculate age from date of birth and group each member into age range in sql

From Dev

Finding date of birth from age in java

From Dev

based on date of birth age not displaying using javascript

From Dev

Convert Date of Birth into Age in Spark Dataframe API

From Dev

Date of birth to Age range using PHP

From Dev

how to add Check constraints on mysql that age calculate from Date of birth field and validate that age is greater than 18

Related Related

  1. 1

    Calculate age based on date of birth

  2. 2

    Calculate age with decimals from date of birth

  3. 3

    Calculate the age using the date of birth

  4. 4

    MySQL Age from Date of Birth (ignore nulls)

  5. 5

    Calculating age with current date and birth date in Java

  6. 6

    Calucate age from birth date in mysql

  7. 7

    How to calculate age from date of birth and group each member into age range in sql

  8. 8

    Calculate age from birth date using NSDateComponents in Swift

  9. 9

    Finding date of birth from age in java

  10. 10

    Pandas get the age from a date (example: date of birth)

  11. 11

    Finding age with date of birth and grouping in terms of age in R

  12. 12

    Calculate age from birth date

  13. 13

    Validating Age from the Date of Birth

  14. 14

    Efficient and accurate age calculation (in years, months, or weeks) in R given birth date and an arbitrary date

  15. 15

    Algolia instantsearch age rangeslider base on date of birth

  16. 16

    SQL. Convert age to date of birth

  17. 17

    search for users age based on date of birth

  18. 18

    Calculate age based on date of birth

  19. 19

    Calculate the age using the date of birth

  20. 20

    SQL Server calculating age from varchar date of birth

  21. 21

    Javascript to calculate a fictional date of birth from todays date and fixed age

  22. 22

    Basic age validation from date of birth in PHP

  23. 23

    Age extracted from birth date always off by inconsistent amount

  24. 24

    How to calculate age from date of birth and group each member into age range in sql

  25. 25

    Finding date of birth from age in java

  26. 26

    based on date of birth age not displaying using javascript

  27. 27

    Convert Date of Birth into Age in Spark Dataframe API

  28. 28

    Date of birth to Age range using PHP

  29. 29

    how to add Check constraints on mysql that age calculate from Date of birth field and validate that age is greater than 18

HotTag

Archive