由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - R: generate random number的问题
相关主题
Help for beginner of Macro请教一道证明题
[R] Generate a set of random number summing up to N[合集] 两个SAS问题
[合集] how to generate 1 to 100k random integer numbers witho[合集] how to randomly generate a n by n positive definite matrix
在R里怎么跳到指定的地方?一个简单问题,关于random number。
Approximate random sampleC programming in statistics
怎样generate random number matrixhow to generate bivariate random sample base on the density function using SAS
moment generating function(mgf)Question for Stratify sampling.
About Gamma Distribution[求教]文献里的一句话,关于MCMC的
相关话题的讨论汇总
话题: 30话题: lb话题: sample话题: generate话题: random
进入Statistics版参与讨论
1 (共1页)
w********n
发帖数: 753
1
现在需要随机抽取5个正的integers,然后这五个数相加需要等于30.怎样在R里实现呢?
多谢各位大侠先。
D******n
发帖数: 2836
2
baozi please.
s=30
n=5
w <- sort(sample(1:(s-1),(n-1)))
draw <-c(w,s)-c(0,w)

呢?

【在 w********n 的大作中提到】
: 现在需要随机抽取5个正的integers,然后这五个数相加需要等于30.怎样在R里实现呢?
: 多谢各位大侠先。

b*****n
发帖数: 685
3
这法子巧是巧,不过只能以相同概率产生随机数,我老到是做了一个function干这事,
是基于multinomial的...
D******n
发帖数: 2836
4
Another limitation of this method is it only generates samples with
replacement.

【在 b*****n 的大作中提到】
: 这法子巧是巧,不过只能以相同概率产生随机数,我老到是做了一个function干这事,
: 是基于multinomial的...

w********n
发帖数: 753
5
Thank you very much, BUT I forgot to mention an extra condition, all the
five generated numbers have to be greater than or equal 2. How do I do that?
PS. thanks for your response, I really appreciate it, could you show me how
to give baozi, I have never done that.

【在 D******n 的大作中提到】
: baozi please.
: s=30
: n=5
: w <- sort(sample(1:(s-1),(n-1)))
: draw <-c(w,s)-c(0,w)
:
: 呢?

w********n
发帖数: 753
6
Do you mind sharing the function?

【在 b*****n 的大作中提到】
: 这法子巧是巧,不过只能以相同概率产生随机数,我老到是做了一个function干这事,
: 是基于multinomial的...

l*********s
发帖数: 5409
7
just transform the question by deducting 10 from 30 and there you go.

that?
how

【在 w********n 的大作中提到】
: Thank you very much, BUT I forgot to mention an extra condition, all the
: five generated numbers have to be greater than or equal 2. How do I do that?
: PS. thanks for your response, I really appreciate it, could you show me how
: to give baozi, I have never done that.

w********n
发帖数: 753
8
Could you please be more specific?

【在 l*********s 的大作中提到】
: just transform the question by deducting 10 from 30 and there you go.
:
: that?
: how

D******n
发帖数: 2836
9
s <- 30
n <- 5
lb <- 1
w <- sort(sample(1:(s-n*lb-1),(n-1)))
draw <- c(w,s-n*lb)-c(0,w)+lb

【在 w********n 的大作中提到】
: Could you please be more specific?
w********n
发帖数: 753
10
Thank you very much.

【在 D******n 的大作中提到】
: s <- 30
: n <- 5
: lb <- 1
: w <- sort(sample(1:(s-n*lb-1),(n-1)))
: draw <- c(w,s-n*lb)-c(0,w)+lb

M****e
发帖数: 178
11
> x <- rep(0, 5)
> while (sum(x)!=30) {
x <- sample(2:22, size=5, replace=T)
}
w********n
发帖数: 753
12
What does "!" mean in while (sum(x)!=30)?

【在 M****e 的大作中提到】
: > x <- rep(0, 5)
: > while (sum(x)!=30) {
: x <- sample(2:22, size=5, replace=T)
: }

n***m
发帖数: 292
13
在sum(x)不等于30的情况下一直sample 直到条件满足才结束循环。不等于的意思

【在 w********n 的大作中提到】
: What does "!" mean in while (sum(x)!=30)?
1 (共1页)
进入Statistics版参与讨论
相关主题
[求教]文献里的一句话,关于MCMC的Approximate random sample
这样还能算Randomized sample吗怎样generate random number matrix
R package: how to use xx.rd files to generate PDF document?moment generating function(mgf)
how to save dataset generated by a function in RAbout Gamma Distribution
Help for beginner of Macro请教一道证明题
[R] Generate a set of random number summing up to N[合集] 两个SAS问题
[合集] how to generate 1 to 100k random integer numbers witho[合集] how to randomly generate a n by n positive definite matrix
在R里怎么跳到指定的地方?一个简单问题,关于random number。
相关话题的讨论汇总
话题: 30话题: lb话题: sample话题: generate话题: random