R错误:格式= NA

时间:2015-11-11 04:25:00

标签: r time min

我正在尝试将我的时间数据分配到15分钟的离散间隔。但是,它显示最小值的错误。有人对此有任何想法吗?

这是我的数据

"10-28-15","00:04:13","13-01","1"
"10-28-15","00:04:16","13-10","1"
"10-28-15","00:04:30","13-11","1"
"10-28-15","11:59:44","13-12","1"
"10-28-15","00:04:48","13-13","1"
"10-28-15","00:04:50","13-14","1"
"10-28-15","00:04:57","13-15","0"
"10-28-15","00:37:57","13-17","0"
"10-28-15","00:45:04","13-17","0"
"10-28-15","00:13:04","13-17","0"

这是我的R剧本:

sample<-read.csv("C:\\Users\\Toshiba\\Desktop\\Parkeasy\\Sunway\\parkeasy.csv",header=FALSE,sep=",")
sample$int<- strptime(paste(sample$V1,sample$V2),format="%m-%d-%y %H:%M:%S")
min_V2<-trunc(min(strptime("2015-10-28 00:00:01", "%d-%m-%y %H:%M:%S"),"min")
max_V2<-trunc(min(strptime("2015-10-28 23:59:59", "%d-%m-%y %H:%M:%S")),"min") + 900
out <- cut(sample$int, breaks = seq(min_V2, max_V2, by = "15 min"))

执行min_V2

时显示错误
min_V2
POSIXlt[1:1] Format:NA

  

seq.int中的错误(0,to0 - from,by):'to'不能是NA,NaN或无限

1 个答案:

答案 0 :(得分:2)

您的日期格式不匹配。

min_V2<-trunc(min(strptime("2015-10-28 00:00:01", "%d-%m-%y %H:%M:%S"),"min")
max_V2<-trunc(min(strptime("2015-10-28 23:59:59", "%d-%m-%y %H:%M:%S")),"min") + 900

而不是%d-%m-%y %H:%M:%S,您希望%Y-%m-%d %H:%M:%S与您的日期字符串匹配。