pmax
is ~ 10x faster than apply
. Still not as fast as colMeans
though.
data = matrix(rnorm(10^6), 100)
data.df = data.frame(t(data))
system.time(apply(data, MARGIN=c(2), max))
system.time(do.call(pmax, data.df))
system.time(colMeans(data))
> system.time(apply(data, MARGIN=c(2), max))
user system elapsed
0.133 0.006 0.139
> system.time(do.call(pmax, data.df))
user system elapsed
0.013 0.000 0.013
> system.time(colMeans(data))
user system elapsed
0.003 0.000 0.002
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…