boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 请教一个R的命令
相关主题
help in R
求助 R sample in matrix form
how to generate 1 to 100k random integer numbers without zeros?
问个面试问题
有个R问题想请交大家
quant analyst 一道概率的面试题
##如果logistic回归自变量x不是线性的,怎么办?##
问R和C的循环语句
R中By函数是什么意思
R table问题弱问
相关话题的讨论汇总
话题: 命令话题: runif话题: bins话题: bin话题: hist
进入Statistics版参与讨论
1 (共1页)
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.

1 (共1页)
进入Statistics版参与讨论
相关主题
R table问题弱问
今天又“R”了 -- 感想和请教。
更新一下Taste of R,再问两个R的问题。
Vectorization question
R program help
How to transpose a data frame in R
How to compute sum of revenue for each day each person in R?
R:如何从vector中挑出单一元素
请教R - 关于mean
怎样用R找出unique的record
相关话题的讨论汇总
话题: 命令话题: runif话题: bins话题: bin话题: hist