11

is there any way to transform output of function microbenchmark::microbenchmark into the data frame or matrix?

For example

v <- rnorm(100)
m <- microbenchmark(mean(v), sum(v))

The output

Unit: nanoseconds
   expr  min     lq    mean median   uq   max neval
mean(v) 6568 6979.5 9348.19   7390 7390 54600   100
 sum(v)    0    1.0  353.57    411  411  8211   100

I want to use this statistics later so I thought about saving the result as data frame. But as.data.frame(m) doesn't work.

Any help appreciated.

jjankowiak
  • 3,010
  • 6
  • 28
  • 45

2 Answers2

15

This will return a data.frame:

summary(m)
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
3

You can save m as a dataframe with the following code:

m <- summary(microbenchmark(mean(v), sum(v))) #note the addition of summary
m.df<- data.frame(m)
User7598
  • 1,658
  • 1
  • 15
  • 28