Dates are represented as the number of days since 1970-01-01, with negative values for earlier dates.
# use as.Date( ) to convert strings to dates
mydates <- as.Date(c("2007-06-22","2004-02-13"))# number of days between 6/22/07 and 2/13/04
days <- mydates[1]- mydates[2]제공
Sys.Date( ) returns today's date.date() returns the current date and time.
The following symbols can be used with the format( ) function to print dates.
You can use the as.Date() function to convert character data to dates. The format is as.Date(x,"format"), where x is the character data and format gives the appropriate format.
# convert date info in format 'mm/dd/yyyy'
strDates <- c("01/05/1965","08/16/1975")
dates <- as.Date(strDates,"%m/%d/%Y")제공
You can convert dates to character data using the as.Character( ) function.
# convert dates to character data
strDates <- as.character(dates)제공
Learning More
See help(as.Date) and help(strftime) for details on converting character data to dates. See help(ISOdatetime) for more information about formatting date/times.
Dates are represented as the number of days since 1970-01-01, with negative values for earlier dates.
Sys.Date( ) returns today's date.date() returns the current date and time.
The following symbols can be used with the format( ) function to print dates.
Here is an example.
Date Conversion
Character to Date
You can use the as.Date( ) function to convert character data to dates. The format is as.Date(x , "format"), where x is the character data and format gives the appropriate format.
The default format is yyyy-mm-dd
Date to Character
You can convert dates to character data using the as.Character( ) function.
Learning More
See help(as.Date) and help(strftime) for details on converting character data to dates. See help(ISOdatetime) for more information about formatting date/times.
To Practice
This intermediate R course includes a section on working with times and dates.