我有一个日期格式为6/16/2019 4:00:00 AM
的csv,被归类为字符。
这是在带有R 3.6的Windows上
所有这些都赋予NA:
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.
我需要将输出格式设置为POSIX类中的2019-06-16 4:00:00