R错误“要替换的项目数不是替换的倍数

R error "number of items to replace is not a multiple of replacement

pdf_1 <- vector()

for(i in 1:100) {
  x <- runif(100, 0, 5)
  pdf_1[i] <- x
}

我也不确定如何得到这个运行,我总是收到同样的错误!

我不确定这是你想要的,但这样你可以用 x:

的值填充 pdf_1
pdf_1 <- vector("double", length = 100)

for(i in 1:100) {
  x <- runif(100, 0, 5)
  pdf_1[[i]] <- x[[i]]
}
head(pdf_1)
[1] 4.4140316 2.8390462 2.7328587 0.5423461 0.1792465 2.2133986

您还需要为 x 放置一个迭代器 i