I want to convert the date data of the string to Date type in R.

Asked 2 years ago, Updated 2 years ago, 36 views

I would like to convert the date data of the string to Date type, but I received the following error.
I don't know what the error code means.

Execution Code

asp<-asp%>%
  select(date, genre_name, amount, device_type)
asp$date<- 
  as.Date(asp$date)

Error Code

Error in
strptime(x,ff): Input string is too long

Input string
date
1 2021-11-0100:04:00
2 2021-11-0100:27:00
3 2021-11-0100:26:00
4 2021-11-0100:04:00
5 2021-11-0100:36:00
6 2021-11-0100:08:00

Thank you for your cooperation.

python r

2022-09-30 15:39

1 Answers

We strongly recommend that you rely on lubidate for this kind of data organization.

 pacman::p_load(tidyverse,lubidate)

>as_datetime("2021-11-0100:04:00")
[1] "2021-11-0100:04:00 UTC"

>as_datetime ("2021-11-0100:04:00", tz="Asia/Tokyo")
[1] "2021-11-0100:04:00 JST"

Please note that as_date() instead of as.date().

In most cases, it is convenient to parse without permission.


2022-09-30 15:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.