-2

I have a column in a data.frame in R that looks like the picture and it is stored as a factor: enter image description here

I need to create a new column in the data.frame that has a data type = date, where this date is the first day of the month. Any ideas of how to create this in an easy way?

Frank
  • 66,179
  • 8
  • 96
  • 180
Darius
  • 489
  • 2
  • 6
  • 22

1 Answers1

5

You can use paste to paste the day with the 'Date' column, convert to Date class using as.Date with the appropriate format argument.

  df1$Date <- as.Date(paste(df1$Date, '01'), '%Y %B %d')

For more info, you can check ?as.Date, ?strptime, ?as.POSIXct

akrun
  • 874,273
  • 37
  • 540
  • 662