Dear R experts
I am reading in a .csv file with readr, where the data is mostly dates and times in separate columns. The 'date' columns are fine to convert with col_type and col_date(%d/%m/%Y), but the 'time' values in the columns are not consistently 4 digits to enable col_time(%H%M) to work properly: there is no leading zero in some of the entries (e.g. "931" representing 09:31).
I know that both the stringr function 'str_pad()' or the Base-R function 'sprintf()' can be used to pad the time column digits out to four, and separately, from that point, col_time(%H%M) will correctly convert the format to a time. However I'm struggling to put these two things together in the readr process.
I have tried:
- nesting both the functions within the readr process
- a pipe to direct the padded 4-digit output of str_pad() to col_time()
- padding the column with str_pad() before defining all the columns with col_type
...with no overall success.
I would be very grateful of any insight or suggestions on how to achieve this.