Skip to content

Instantly share code, notes, and snippets.

@bohdanszymanik
Created May 24, 2021 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bohdanszymanik/a4000a2bbcf6e2c4ae573b6805b02961 to your computer and use it in GitHub Desktop.
Save bohdanszymanik/a4000a2bbcf6e2c4ae573b6805b02961 to your computer and use it in GitHub Desktop.
Random date formatting example in R so I don't forget how it's done
library(readr)
library(stringr)
library(stringi)
em <- read_csv("C:/somewhere/some.csv")
em$Time <- paste(
paste(str_sub(em$`Date & Time`, 7, 10), str_sub(em$`Date & Time`, 4, 5), str_sub(em$`Date & Time`, 1, 2), sep="/"),
str_sub(em$`Date & Time`, -8), sep = " "
)
library(lubridate)
ymd_hms(em$Time)
em$TimeStart <- ymd_hms(em$Time)
em$TimeEnd <- em$TimeStart + minutes(1)
em$TimeStartStr <- format( em$TimeStart, "%Y-%m-%d %H:%M:%OS", tz = "UTC")
em$TimeEndStr <- format(em$TimeEnd, "%Y-%m-%d %H:%M:%OS", tz = "UTC")
write_csv(em, "C:/somewhereelse/some.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment