Skip to content

Instantly share code, notes, and snippets.

@Myfanwy
Created November 24, 2015 22:15
Show Gist options
  • Save Myfanwy/d1f717904a32e3870e00 to your computer and use it in GitHub Desktop.
Save Myfanwy/d1f717904a32e3870e00 to your computer and use it in GitHub Desktop.
All the ways I know to get things in the right date/time format
# All of my times are in mm/dd/yyyy hh:mm:ss
# From a character string (read in from read.csv(stringsAsFactors = FALSE))
# By far the easiest way is with lubridate::mdy_hms()
#Ex:
options(stringsAsFactors = FALSE)
Sys.timezone(location = FALSE)
Sys.setenv(TZ = "Pacific/Pitcairn")
Sys.timezone() # make sure it took
files <- list.files(pattern = "*.csv") #create list of files by character name; change working directory first
d <- plyr::adply(files, 1, read.csv) #combine into one big dataframe
colnames(d) <- c("DateTimeUTC", "Monitor" , "TagID")
d$DateTimeUTC <-mdy_hms(f$DateTimeUTC) # Convert to POSIXct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment