Skip to content

Instantly share code, notes, and snippets.

@whatever
Created March 14, 2013 13:51
Show Gist options
  • Save whatever/5161466 to your computer and use it in GitHub Desktop.
Save whatever/5161466 to your computer and use it in GitHub Desktop.
Example of how to make a data-time data set in R
# Create 3 date data-points
date.time1 <- as.POSIXct(strptime('2011-03-27 01:30:00', '%Y-%m-%d %H:%M:%S'))
date.time2 <- strptime("12/20/10 14.34.35", format = "%m/%d/%y %H.%M.%S")
date.time3 <- as.Date("12/15/20", format = "%m/%d/%y")
# Cast one as POSIXlt
date.posix1 <- as.POSIXlt(date.time1)
# Place dates in their columns
all.dates <- data.frame(x = date.time1, y = date.time3, z = date.time3, a = date.posix1)
# Output data.frame
all.dates
# Save file locally
save(all.dates, file = "./dates_r_all.Rdata")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment