![]() |
VOOZH | about |
In this article, we will discuss how to convert Numbers to Dates in R programming language.
Here we have to consider an integer and then first we have to convert that integer into a character using as.character() function and then convert that character using as.Date() function and finally convert into date using "%Y%m%d" format
Syntax:
as.Date(as.character(integer),format = "%Y%m%d")
where, an integer is an input number
Example: Convert Numbers to date
Output:
[1] "2021-11-02" [1] "2020-12-09"
strptime() is used to convert into the date from an integer in the "%Y%m%d" format
Syntax:
strptime(integer, format = "%Y%m%d")
Example: Convert Numbers to date
Output:
[1] "2021-11-02 UTC" [1] "2020-12-09 UTC"
Here ymd() is used to convert the integer into year, month, and date which is available in lubridate() package
Syntax:
ymd(integer)
Example: Convert Numbers to date
Output:
[1] "202-11-12" [1] "2020-12-09"