h***t 发帖数: 2540 | 1 如果我用R产生了随机数,然后把它分成几个bins,如果数在每个bin里面的number of
observation,最好能执行效率高一点
e.g x<-runif(1000)
how to get the # in each bin from [0,0.1],[0.1,0.2],....[0.9,1]
多谢 | s*****n 发帖数: 2174 | 2 x <- runif(1000)
tapply(x, round(x + 0.05, 1), length) | h***t 发帖数: 2540 | 3 works fine, thanks
what if I want the results for unequal length bins, say 0.1,0.2,0.3,0.4.
【在 s*****n 的大作中提到】 : x <- runif(1000) : tapply(x, round(x + 0.05, 1), length)
| s*****n 发帖数: 2174 | 4 那你就干脆用内置的函数好了, 比如 hist
hist(x, breaks = c(0, 0.1, 0.2, 0.5, 0.7, 1), freq = T)$count
【在 h***t 的大作中提到】 : works fine, thanks : what if I want the results for unequal length bins, say 0.1,0.2,0.3,0.4.
|
|