Today is my 10,000 days old birthday
[This article was first published on Data science & Software development » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I’ve been calculated my day of 10,000 days old birthday in R since few days ago.
I found that to calculate this in R is quite simple.
My birthday to 10,000 days old birthday:
> as.Date("1986-09-21") + 10000 [1] "2014-02-06"
Birthday to days since my birthday:
> Sys.Date() - as.Date("1986-09-21") Time difference of 10000 days
Just for reference, below is an R function to convert a birthday to age.
# Birthday to age birthday2age <- function(birthday){ td.y <- as.integer(format.Date(Sys.Date(),"%Y")) td.m <- as.integer(format.Date(Sys.Date(),"%m")) td.d <- as.integer(format.Date(Sys.Date(),"%d")) bd.y <- as.integer(format.Date(birthday,"%Y")) bd.m <- as.integer(format.Date(birthday,"%m")) bd.d <- as.integer(format.Date(birthday,"%d")) return(td.y-bd.y-(td.m<bd.m||(td.m==bd.m&&td.d<bd.d))) } > birthday2age("1986-09-21") [1] 27
Reference:
年齢の計算は暗算でもできる
To leave a comment for the author, please follow the link and comment on their blog: Data science & Software development » R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.