05:00:00 - 28:59:59时间格式功能

时间:2014-06-19 14:11:11

标签: r function date posixct

我想创建处理问题的函数: 05:00:00 - 28:59:59 time format

当我从该问题运行脚本时,它正在运行但是当我运行该函数时:

 pal <- NormalDates(data,Date,Time.start)
Error in unclass(e1) + unclass(e2) : 
  non-numeric argument to binary operator
Called from: `+.POSIXt`(as.POSIXct(as.character(df$day), format = "%d.%m.%Y"), 
    sapply(strsplit(as.character(df$time), ":"), function(t) {
        t <- as.integer(t)
        t[3] + t[2] * 60 + t[1] * 60 * 60
    }))
Browse[1]>  

如何摆脱这个错误?

我的功能:

NormalDates <- function(df,day,time) {
    # Function transforms 05:00:00 - 28:59:59 time to usual date vector
    #
    # Args: 
    #    df: data frame that contains  datasheet
    #    date: column name with date
    #    time: column name with time
    #
    # Returns:
    #    Vector with normal dates of class "POSIXct"

    # Error handling
if (class(df) != "data.frame") {
    stop("Not a data.frame object")
} 

arguments <- as.list(match.call())
day = eval(arguments$day, df)
time = eval(arguments$time, df)

#New date vector generating
pal <- as.POSIXct(as.character(df$day), format="%d.%m.%Y") +
    sapply(strsplit(as.character(df$time), ":"), function(t) {
        t <- as.integer(t)
        t[3] + t[2] * 60 + t[1] * 60 * 60
    })
return(pal)
}

0 个答案:

没有答案