2 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
您的rbind方法應(yīng)該可以正常工作。您也可以使用
rpois(lambda=c(3,4),n=1e6)
因?yàn)镽會(huì)自動(dòng)將lambda值向量復(fù)制到所需的長(zhǎng)度。速度差別不大:
library(rbenchmark)
benchmark(rpois(1e6,c(3,4)),
c(rbind(rpois(5e5,3),rpois(5e5,4))))
# test replications elapsed relative
# 2 c(rbind(rpois(5e+05, 3), rpois(5e+05, 4))) 100 23.390 1.112168
# 1 rpois(1e+06, c(3, 4)) 100 21.031 1.000000
當(dāng)然,這種c(rbind(...))方法通常適用于構(gòu)造交替向量,而其他解決方案特定于rpois或以這種方式復(fù)制其參數(shù)的其他函數(shù)。
- 2 回答
- 0 關(guān)注
- 709 瀏覽
添加回答
舉報(bào)