The as.Date()
function in R converts a date character to an object whose class is Date
.
as_Date(x)
The as.Date()
function takes a single and mandatory parameter value, x
, which represents the character representation of a date.
The as.Date()
function returns an object whose class is "Date"
.
# creating a data characterdate_in_string <- "2022-01-29"# calling the as.Date() functionmy_date = as.Date(date_in_string)print(my_date)# cheking the classclass(my_date)
date_in_string
variable.as.Date()
function on the date_in_string
variable. The result is assigned to a variable, my_date
.my_date
.class()
function to check for the class of the object variable my_date
.