Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从R中的具体分布减少数字生成器的序列_R_Random_Sequence_Normal Distribution - Fatal编程技术网

从R中的具体分布减少数字生成器的序列

从R中的具体分布减少数字生成器的序列,r,random,sequence,normal-distribution,R,Random,Sequence,Normal Distribution,我是R的新手,如果我问了一个愚蠢的问题,很抱歉。 我试图从正态分布生成随机数,因为它们将形成一个递减的数字序列,这意味着当Y_n

我是R的新手,如果我问了一个愚蠢的问题,很抱歉。 我试图从正态分布生成随机数,因为它们将形成一个递减的数字序列,这意味着当Y_n 我知道我必须使用一些for和while循环,但我不知道如何使用

非常感谢。

x诸如此类:

x <- rnorm(2)
i  <- 1
while (x[i] >= x[i+1]){
  x[i+2] <- rnorm(1)
  i <- i + 1
}
if (x[i] < x[i+1]) x <- x[1:i] 
vals <- rnorm(n = 2)
idx <- length(vals)
while(vals[idx - 1] < vals[idx]) {
  vals <- append(x = vals, values = rnorm(n = 1))
  idx <- idx + 1
}
vals如果希望“高概率”避免向量增长,可以成批生成数字。批量大小为10的情况下,即使只需增长一次向量,也不太可能

就性能而言,我不知道什么更快

rnormdec
append(x,values)
c(x,values)
的包装器,因此您正在执行verboten
x