0
votes

I have some data that shows the date only in year-month, this makes it difficult to work with in plots etc, because of the character. as.Date does not work in this case. So how can I use tibble to format this into year-month-day?

This is what I have tried

tibble(USTB$Dates)
tibble(USTB$Dates, "1934-01")
tibble(USTB$Dates, paste0("1934-01", "-01"))
tibble(ymd(paste0("1934-01", "-01")))

I get the change to year-month-day, but it only changes for the first day, meaning every date is now 1934-01-01.

Any ideas?

1
Right now it's pretty unclear what you're doing. I'm assuming ymd is from lubridate, but it's good to include what packages you're working with. Without having any of your data, we can't recreate this, and for a question about formatting that's pretty crucial. You've also just created a column that is nothing more than "1934-01-01"—what were you trying to do there, and what did you expect to happen? - camille

1 Answers

0
votes

This works for me to add day (-01) and convert to date (to make it easier to work with in plots):

USTB$Dates <- as.Date(paste0(USTB$Dates, "-01"))