How about this with cut()
? I've returned a list so that the time comes out as well, but you can just return the bins. Also, I added 5 bins to cater for the 4 q points, 0-min and max-Inf:
binner <- function(N=1000){
vec<-runif(N)
timer<-system.time(ret<-cut(vec,breaks<-c(0,quantile(vec, seq(0, 0.75, 0.25)),Inf),labels=1:5))
list(ret,timer)
}
binner(10000000)
...
[[2]]
user system elapsed
4.55 0.12 4.70