来自包chron奇怪格式的R函数times()

时间:2018-09-07 13:02:06

标签: r chron

带有chron包中的times函数的非常简单的“ times(3/24)”操作将导致:

> times(3/24)  
[1] 03:00:00

当我在数据框中使用它时,它的格式不正确。而是写入原始数字“ 0.125”。但是,当我将它包含在ifelse()语句中时,它可以工作。

查看示例:

> X<-seq(1,10,1)  
> tdata<-as.data.frame(X)  
> tdata$T3AM<-times(3/24)  
> tdata$T3AMx<-times(ifelse(tdata$X>0,3/24,3/24))  
> tdata  
    X  T3AM    T3AMx  
1   1 0.125 03:00:00  
2   2 0.125 03:00:00  
3   3 0.125 03:00:00  
4   4 0.125 03:00:00  
5   5 0.125 03:00:00  
6   6 0.125 03:00:00  
7   7 0.125 03:00:00  
8   8 0.125 03:00:00  
9   9 0.125 03:00:00  
10 10 0.125 03:00:00    

对此有什么解释吗?

1 个答案:

答案 0 :(得分:0)

问题是chron中的function sendVoice($chat_id, $voice, $caption) { $filepath = realpath($_FILES['file']['tmp_name']); $post_data = array( 'chat_id' => $chat_id, 'voice' => new CURLFile($filepath), 'caption' => $caption ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $GLOBALS['api'].'/sendVoice'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_exec($ch); curl_close($ch); } 类未提供$post_data方法。如果我们添加一个就可以了。

"times"

给予:

rep

请注意,Kurt刚刚将library(chron) rep.times <- function(x, ...) times(rep(as.numeric(x), ...)) # from question: X <- seq(1,10,1) tdata <- as.data.frame(X) tdata$T3AM <- times(3/24) tdata$T3AMx <- times(ifelse(tdata$X>0,3/24,3/24)) 添加到了2.3-53版,现在应该在CRAN上。