R で 05:30 (5 分 30 秒) などの時間帯を処理する良い方法はありますか?
あるいは、数秒で整数に変換する最速の方法は何ですか?
日付にしか変換できず、時間のデータ型を実際に見つけることができません。
私はZooでRを使用しています。
どうもありがとう !
Seconds がこれに対処する最良の方法でした。以下のシェーンのコードを目的に合わせて調整しました。結果は次のとおりです。
# time - time in the format of dd hh:mm:ss
# (That's the format used in cvs export from Alcatel CCS reports)
#
time.to.seconds <- function(time) {
t <- strsplit(as.character(time), " |:")[[1]]
seconds <- NaN
if (length(t) == 1 )
seconds <- as.numeric(t[1])
else if (length(t) == 2)
seconds <- as.numeric(t[1]) * 60 + as.numeric(t[2])
else if (length(t) == 3)
seconds <- (as.numeric(t[1]) * 60 * 60
+ as.numeric(t[2]) * 60 + as.numeric(t[3]))
else if (length(t) == 4)
seconds <- (as.numeric(t[1]) * 24 * 60 * 60 +
as.numeric(t[2]) * 60 * 60 + as.numeric(t[3]) * 60 +
as.numeric(t[4]))
return(seconds)
}