The date columns in my df have only year and month as a string (eg "2009-09"
), and therefore conversion to datetime using as.POSIXct
doesn't seem to work.
I considered the following solution to fix this:
df$col <- past0(df$col, '-01')
df$col <- as.POSITXct(df$col, format='%Y-%m-%d', tz='UCT')
Which seems to work. My questions are:
- Is this indeed an acceptable solution or may I encounter problems further down the line?
- Is there a way of dealing with this directly with
as.POSITXct
that would make redundant the line that pastes the day?
EDIT for any future readers: My question is answered here Converting year and month ("yyyy-mm" format) to a date?
I couldn't find it during my initial searches.