-2

I am trying converting a column having values as character from Dataframe, to date values. But after converting the column values turned into 'NA'.

Here is my code:

library(rvest)
library(dplyr)
dvpact <- "https___covidlive.com.au_report_daily-vaccinations-people_act.html"
dvpactpage <- read_html(dvpact)
dvpactp <- dvpactpage %>% html_nodes("table.DAILY-VACCINATIONS-PEOPLE") %>% html_table() %>% .[[1]]
dvpactp$Date <- as.Date(dvpactp$Date, format = "%m-%d-%Y")
dvpactp

After the above conversion from character to date, the DATE column values shows 'NA'. Can anyone help me on this issue, please? Thanks in advance.

Sanky Ach
  • 333
  • 8
  • 23
  • Check this: https://stackoverflow.com/questions/15566875/as-date-returning-na-while-converting-from-ddmmmyyyy – Ravindra S Jun 26 '22 at 17:50

1 Answers1

0

your link doesn't work, but if the format is 27 Jun 22 like on this page: https://covidlive.com.au/report/daily-vaccinations/aus,

then you'll need to change the format argument inside this line:
dvpactp$Date <- as.Date(dvpactp$Date, format = "%m-%d-%Y")
to format="%d %b %y"

Russ
  • 1,385
  • 5
  • 17
  • Error: Assigned data `as.Date(dvpactp$Date, format = "%d %b %y")` must be compatible with existing data. x Existing data has 458 rows. x Assigned data has 0 rows. i Only vectors of size 1 are recycled. Run `rlang::last_error()` to see where the error occurred. In addition: Warning message: Unknown or uninitialised column: `Date`. – Sanky Ach Jun 27 '22 at 03:40
  • Can you provide a working link? I think the problem is happening before the date conversion step – Russ Jun 27 '22 at 22:30