【问题标题】:Convert H2OFrame object from milliseconds to Minutes?将 H2OFrame 对象从毫秒转换为分钟?
【发布时间】:2018-05-17 15:05:16
【问题描述】:

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() 函数?

【问题讨论】:

    标签: r h2o


    【解决方案1】:

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

    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
    

    【讨论】:

      猜你喜欢
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-31
      • 2018-11-16
      • 2013-01-12
      • 1970-01-01
      • 2014-02-13
      相关资源
      最近更新 更多