使用 Sys.time() 创建的铸造对象
Casting object created with Sys.time()
我正在测量嵌套 foreach 循环中几个函数的性能,以便做到这一点
start <- Sys.time()
<corpus of function>
end <- Sys.time()
diff_time = end - start
问题是后记对象假定 class“diff_time”,我无法用 ggplot2 绘制它。
有没有可能一些比其他模拟速度更快的模拟会有后缀 sec 而其他的有 mins?如果发生这种情况,我该如何避免这些问题?
您可以在将 difftime 转换为 numeric 时指定单位。
t = difftime(time1 = "2016-01-02 01:00:00", time2 = "2016-01-02 00:30:00")
t
# Time difference of 30 mins
as.numeric(t, units = "secs")
# [1] 1800
我正在测量嵌套 foreach 循环中几个函数的性能,以便做到这一点
start <- Sys.time()
<corpus of function>
end <- Sys.time()
diff_time = end - start
问题是后记对象假定 class“diff_time”,我无法用 ggplot2 绘制它。
有没有可能一些比其他模拟速度更快的模拟会有后缀 sec 而其他的有 mins?如果发生这种情况,我该如何避免这些问题?
您可以在将 difftime 转换为 numeric 时指定单位。
t = difftime(time1 = "2016-01-02 01:00:00", time2 = "2016-01-02 00:30:00")
t
# Time difference of 30 mins
as.numeric(t, units = "secs")
# [1] 1800