将H2OFrame对象从毫秒转换为分钟?

时间:2018-05-16 09:57:09

标签: r h2o

H2O-R-Package提供的功能是将H2OFrame对象的条目从毫秒提取/转换为:

  • 年份 h2o.year()
  • 月 h2o.month()
  • 小时 h2o.hour()
  • 日 h2o.day()
  • 星期几 h2o.dayOfWeek()
  • 但几分钟没什么......

自小时开始以来,如何将H2OFrame对象的条目从毫秒转换为分钟?

data.hex = h2o.importFile(filetoload, sep = "," )
date.hex = data.hex[,3] 

#Number of minutes since the begining of Hour
date_epoch = as.data.frame(date.hex)
date_formated = apply(date_epoch , 1, function(x){
    date_format =  as.POSIXlt(x, origin="1970-01-01", tz="HKT")
    return(date_format)
} )

minu =  unlist(lapply(date_formated, function(x){

    return(x$min)
}))
minu.hex = as.h2o(minu)

与以下代码相比,此代码的计算时间非常长:

#Hour of day
heure.hex = hour(date.hex)

有没有更好的解决方案? 为什么没有任何h2o.minute()函数?

1 个答案:

答案 0 :(得分:1)

我使用modulo找到了更好的解决方案:

data.hex = h2o.importFile(filetoload, sep = "," )
date.hex = data.hex[,3] 

#Number of minutes since the begining of Hour
#Divide by 1000 to work with seconds and Extract minutes + seconds
#Remove seconds and format in minutes
minu.hex = ((date.hex/1000)%%(60*60))%/%60