How do I create a column that populates a specific value for a date?

Data <-  
  Data %>%
  mutate(date = as.Date('2018-02-31' ,  format = "%Y%m%d"))

This produces a new column of NA values.

When I try not specifying a format, I get this error:

Error: Problem with `mutate()` column `date`.
ā„¹ `date = as.Date("2018-02-31")`.
x character string is not in a standard unambiguous format

I am trying to create a new column, date that that has the value 2018-02-31 in the YYYY-MM-DD repeating, as the Date data type..

Does anyone have any ideas? Thank you.

I also have a character column with repeating values of 02/31/2018 that I could convert to date type YYYY-MM-DD but am not having luck with that either.

I would like something like this (Date as Date type when you glimpse it):

|id|Animal |Date|
|1 |Dog|2018-02-31|
|2 |Dog|2018-02-31|
|3 |Cat |2018-02-31|

Any help would be appreciated. I'm not sure why this is happening.

2018-02-31 is not a valid date. Try 2018-02-28.

DF <- DF %>%
  mutate(date = as.Date('2018-02-28' ,  format = "%Y-%m-%d"))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.