Created
May 24, 2021 02:30
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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