Calculate ages in R

前端 未结 8 1766
北荒
北荒 2020-11-27 16:39

I have two data frames in R. One frame has a persons year of birth:

YEAR
/1931
/1924

and then another column shows a more recent time.

8条回答
  •  有刺的猬
    2020-11-27 17:29

    I think this might be a bit more intuitive and requires no formatting or stripping:

    as.numeric(as.Date("2002-02-02") - as.Date("1924-08-03")) / 365
    

    gives output:

    77.55342
    

    Then you can use floor(), round(), or ceiling() to round to a whole number.

提交回复
热议问题