Дата не форматируется в POSIX, всегда превращается в NA - PullRequest
0 голосов
/ 25 июня 2019

У меня есть CSV с форматом даты в 6/16/2019 4:00:00 AM, который классифицируется как символ.

Это на Windows с R 3,6

Все это дает НС:

wbvdf$timestamp <-as.POSIXct(wbvdf$timestamp, format = "%m/%d/%Y %H:%M:%S")

wbvdf$timestamp <-as.POSIXct(wbvdf$timestamp, format = "%m/%d/%Y %H:%M:%S", tz = "Africa/Nairobi")

wbvdf$timestamp <- as.POSIXct(wbvdf$timestamp,"6/1/2019 4:00", format="%m/%d/%Y", tz="Africa/Nairobi")

head(wbvdf)
   timestamp     
1:      <NA> 
2:      <NA> 

Они дают разные ошибки:

wbvdf$timestamp <- as.POSIXct(wbvdf$timestamp, tz="GMT")  

Error in as.POSIXlt.character(x, tz, ...) : 
  character string is not in a standard unambiguous format

wbvdf$timestamp <- as.POSIXlt(wbvdf$timestamp, tz = "Africa/Nairobi", format = c("%m-%d-%Y %H:%M"))

Error in `[<-.data.table`(x, j = name, value = value) : 
  Supplied 11 items to be assigned to 2268 items of column 'timestamp'. The RHS length must either be 1 (single values are ok) or match the LHS length exactly. If you wish to 'recycle' the RHS please use rep() explicitly to make this intent clear to readers of your code.

Мне нужно, чтобы вывод был отформатирован как 2019-06-16 4:00:00 в классе POSIX

...