R - faster alternative to hist(XX, plot=FALSE)$count
问题 I am on the lookout for a faster alternative to R's hist(x, breaks=XXX, plot=FALSE)$count function as I don't need any of the other output that is produced (as I want to use it in an sapply call, requiring 1 million iterations in which this function would be called), e.g. x = runif(100000000, 2.5, 2.6) bincounts = hist(x, breaks=seq(0,3,length.out=100), plot=FALSE)$count Any thoughts? 回答1: A first attempt using table and cut : table(cut(x, breaks=seq(0,3,length.out=100))) It avoids the extra