I have a dataframe with a column of dates in YYYYMMDD format. I would like to convert this column of values to YYYY_MM_DD to match the format in another database.
Solutions I have found primarily focus on splitting a strings such as comma-delimited.
I essentially want a solution that indexes YYYYMMDD and inserts an '_' after the 4th character and the 6th character.
Thanks
UPDATE:
After posting I almost immediately found a solution that worked for me:
library(tidyr)
# create names for new columns
newCol <- c("YEAR", "MONTH", "DAY")
# separate existing column at 4 and 6 character
newData <- separate(table, old_column, newCol, sep = c(4,6))
# combining the three columns to one delimited by '_'
table$newColumn <- paste(table$YEAR, table$MONTH, table$DAY, sep = "_")