Parsing dates in R from strings with multiple formats

后端 未结 1 1253
感动是毒
感动是毒 2021-01-25 03:53

I have a tibble in R with about 2,000 rows. It was imported from Excel using read_excel. One of the fields is a date field: dob. It imported as a string, and has dates in three

1条回答
  •  闹比i
    闹比i (楼主)
    2021-01-25 04:12

    We create a logical index after the first run based on the NA values and use that to index for the second run

    i1 <- is.na(dob_fixed)
    dob_fixed[i1] <- as.Date(as.integer(dob[i1]), origin = "1899-12-30")
    

    0 讨论(0)
提交回复
热议问题