library(onezero)
library(microbenchmark)
library(collapse)
library(tidyverse)
xx <- runif(1e+6)
na.index <- sample(
x = 1:length(xx),
size = length(xx) / 10,
replace = FALSE
)
yy <- xx
yy[na.index] <- NA
microbenchmark(
"stats" = weighted.mean(xx, xx),
"ozc++" = weighted_mean_cpp(xx, xx),
"fmean" = fmean(x = xx, w = xx),
"stats_miss" = weighted.mean(yy, xx, na.rm = TRUE),
"ozc++_miss" = weighted_mean_cpp(yy, xx, na.rm = TRUE),
"fmean_miss" = fmean(x = yy, w = xx),
times = 50,
unit = "s"
)
rnd <- 13
round(weighted.mean(yy, xx, na.rm = TRUE), rnd) == round(fmean(x = yy, w = xx), rnd)
weighted.mean(xx, xx) == weighted_mean_cpp(xx, xx)
weighted.mean(yy, xx, na.rm = TRUE) == fmean(x = yy, w = xx)
mtm <- as.matrix(mtcars)
microbenchmark(
rowSums(qM(mtcars)),
rowSums(mtcars),
Rfast::rowsums(mtm)
)
microbenchmark(
tapply(mtcars$mpg, mtcars$cyl, mean),
fmean(mtcars$mpg, g = mtcars$cyl)
)
microbenchmark(
fselect(mtcars, cyl),
select(mtcars, cyl)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.