根据以下基准,which
比不使用which
快约5%。有谁知道为什么?
> microbenchmark(mtcars[mtcars$gear == 4 | mtcars$gear == 3,], times = 100000)
Unit: microseconds
expr min lq mean median uq max neval
mtcars[mtcars$gear == 4 | mtcars$gear == 3, ] 179.104 190.334 212.0044 194.876 199.662 85451.69 1e+05
> microbenchmark(mtcars[which(mtcars$gear == 4 | mtcars$gear == 3),], times = 100000)
Unit: microseconds
expr min lq mean median uq max neval
mtcars[which(mtcars$gear == 4 | mtcars$gear == 3), ] 168.744 179.569 196.0215 184.326 188.981 75434.62 1e+05