The NA
's are throwing it off (i.e. it has nothing to do with the # of bins). Here's a slightly modified f()
with both plotting disabled for hist
(it's unlikely you want plots) and with handing a column subset that's all NA
's
f <- function(x) {
y <- x[!is.na(x)]
if (length(y) > 0) {
hi <- hist(x, plot=FALSE)
speedmph <- round(hi$breaks*0.68,1)
prob <- c(0, round(cumsum(hi$counts) / sum(hi$counts), digits=2))
cbind(speedmph, prob)
} else { # still need to return proper sized values
cbind(rep(NA, length(x)), rep(NA, length(x)))
}
}