0

I'm trying to convert one column in my dataframe into a DATE object.

My data frame named k contains two columns. salinity is a numeric while date is a character.

  salinity      date
    0.1      Mar-17
    1.1      Jun-17
    16.0     Aug-17
    0.5      Nov-17

So, I tried the usual way

k$date = as.Date(k$date, "%b-%y")

It returns a string of NA

I think I've already viewed the most of the threads here in Stackoverflow that resembles my problem. I tried all the solutions/comments in those threads but to no avail.

So I decided to create a vector containing all the dates and tried to convert them. I plan to just paste the values later on. But it still returns a string of NA values. I'm really confused since I already did this a month ago with another dataset and it went swimmingly.

zx8754
  • 52,746
  • 12
  • 114
  • 209
ohnmiel
  • 1
  • 1
  • From the linked post, try `as.Date(paste("01-", "Mar-17", sep = ""), format = "%d-%b-%y")` To convert to date format, we need to have DAY, too. So we are pasting dummy `01` first of month, then converting to date. – zx8754 Aug 01 '18 at 07:37
  • 1
    Oh! I've never encountered this problem before, it never crossed my mind that R needs a day input, too; so that's why it was rejecting my commands. Many thanks!! – ohnmiel Aug 01 '18 at 08:02

0 Answers0