【问题标题】:R system.time() as a numberR system.time() 作为数字
【发布时间】:2016-03-17 09:05:53
【问题描述】:

我正在使用 system.time() 函数来测量我的代码经过的时间,但我需要它是一个数字才能将其绘制成图表。不幸的是 system.time() 输出的结构比数字更复杂,像这样:

   user  system elapsed 
  0.101   0.000   0.100 

我想将此结构转换为数字,用户经过的时间会很棒 => 0.101

我试过 as.double(tt$elapsed[[1]]) 但还不是一个数字。有什么帮助吗?

提前致谢!

【问题讨论】:

  • 你应该使用str来研究对象的结构,而不是盲目的希望。
  • 谢谢,@Roland str() 是一个我不知道的好工具。在这种情况下,它的输出是Class 'proc_time' Named num [1:5] 0 0 0 0 0 ..- attr(*, "names")= chr [1:5] "user.self" "sys.self" "elapsed" "user.child" ...

标签: r data-structures casting decimal benchmarking


【解决方案1】:

tt 对象是proc_time 类,实际上是一个Named 数字。所以,基本上是一个名为vector

unname(tt[3])

或者正如@Matthew Plourde 提到的那样

tt[['elapsed']]

也可以使用。

【讨论】:

  • 另一个选项是tt[['elapsed']]
猜你喜欢
  • 1970-01-01
  • 2017-08-15
  • 1970-01-01
  • 1970-01-01
  • 2015-04-18
  • 2023-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多