Skip to content

@mollietaylor /dateFormats.R
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Date Formats in R
# importing dates:
dates <- c("05/27/84", "07/07/05")
betterDates <- as.Date(dates,
format = "%m/%d/%y") # here you put the format your dates are currently in
# it will output the ISO standard dates (%Y-%m-%d)
# or:
dates <- c("May 27 1984", "July 7 2005")
betterDates <- as.Date(dates,
format = "%B %d %Y")
betterDates
# from Windows Excel:
dates <- c(30829, 38540)
betterDates <- as.Date(dates,
origin = "1899-12-30")
betterDates
# from Mac Excel:
dates <- c(29367, 37078)
betterDates <- as.Date(dates,
origin = "1904-01-01")
betterDates
# using dates:
format(betterDates,
"%a %b %d")
mean(betterDates)
max(betterDates)
min(betterDates)
# fixing centuries:
dates <- c("05/27/84", "07/07/05", "08/17/20")
betterDates <- as.Date(dates, "%m/%d/%y")
correctCentury <- as.Date(ifelse(betterDates > Sys.Date(),
format(betterDates, "19%y-%m-%d"),
format(betterDates)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.