如何在 R 中生成标准正态随机数?


标准正态分布是平均值等于 0,标准差为 1 的分布类型。如果我们想要生成标准正态随机数,可以使用 R 的 rnorm 函数,但需要将平均值 = 0 和标准差 = 1 传递给此函数。

示例

 在线演示

rnorm(10,0,1)

输出

[1] 0.6936607 -0.7967657 -2.7544428 0.2688767 0.5278463 -1.5387568
[7] 1.1716632 -1.5033895 0.8112929 -1.0101065

示例

 在线演示

rnorm(50,0,1)

输出

[1] 2.58246666 -0.53083341 -0.57343343 1.08172756 1.30341849 -0.07440422
[7] -0.41869305 -0.96227706 -0.46899119 1.55428279 0.09162738 -0.96027221
[13] -0.84735327 -1.74949782 0.58541758 0.23117630 0.47402479 -0.72453853
[19] 0.07171564 1.13088794 0.18735157 0.25091758 -1.34728315 -0.39768159
[25] -0.38109955 -0.34019286 -1.51778561 -0.92222239 -1.22798041 -0.77350032
[31] -1.65852274 0.51227977 0.83822730 0.45359267 0.49714674 -1.47674552
[37] -0.01242228 1.60937112 0.38869615 1.73720338 0.56832087 -0.35619856
[43] -1.74371897 -0.77162373 -1.80142363 -0.92801065 0.92791947 0.14078622
[49] -1.55200961 -0.06995120

示例

 在线演示

rnorm(60,0,1)

输出

[1] -0.98030635 0.14934486 -1.55025640 0.80780101 -0.54240515 0.14488726
[7] 2.89290245 1.10729520 0.08050478 -0.44497057 1.10941494 1.74939247
[13] 0.84032675 0.47427879 0.11898992 1.85356655 0.19312780 -0.47810793
[19] 2.36569993 -0.45530246 -0.81494824 -1.99941347 -0.50359976 0.55592840
[25] 1.14048452 -1.02259883 -1.17629055 1.48930583 1.76136612 0.70749370
[31] 0.88976803 0.87302066 -0.90594396 -0.92584519 -0.57771767 -2.01680635
[37] 1.25990880 0.87272304 3.86728923 0.48660167 2.12238845 -1.23884756
[43] -0.29534035 -1.66654062 -0.92580904 0.46701435 -0.27171548 -0.79118171
[49] -1.87119180 -1.43572885 3.60672069 0.58631139 -0.38245860 0.62229426
[55] -0.54297322 -2.39866511 -1.91755583 -0.61459590 0.11865738 0.65653693

示例

 在线演示

rnorm(80,0,1)

输出

[1] -0.21167734 1.00334018 0.58986878 -1.15025242 0.83748340 0.04415646
[7] 0.21006101 -0.35285172 -0.53306794 -0.31683124 -0.15284674 1.72136890
[13] 0.67868984 -0.40103797 0.19409371 -0.31236848 1.08174032 0.82741254
[19] 1.52301592 0.92592501 -1.13193294 -0.52651889 -0.22310016 -0.93938644
[25] 0.27894221 -2.89894569 0.36546350 0.84345631 -0.81706708 0.18261437
[31] -0.69591250 1.09539577 -1.15864497 -0.22639388 -0.32866906 -1.12182835
[37] -0.08435003 1.81382691 0.04255180 -0.32941539 2.64070059 1.56935548
[43] -0.24635038 0.62292947 1.05232124 0.67012389 0.91400357 0.26348570
[49] -0.35494585 1.09602375 -1.39164787 -0.36638726 1.76550599 -0.22423221
[55] -0.33138915 -0.66652623 -0.50509947 -0.93338252 -2.70014038 -0.52016919
[61] 0.80396082 0.75912405 0.52966924 0.76088675 0.87390249 0.19404944
[67] -0.94092779 -1.20741440 -1.28536191 0.03052385 -2.23973254 -0.39531601
[73] -0.84322501 0.78849127 1.70032152 1.11591005 -1.15304534 -1.23219567
[79] 0.91807504 1.21157462

示例

 在线演示

rnorm(100,0,1)

输出

[1] -0.60163722 0.62726820 -0.78769462 0.72244706 -0.57654069 0.21386083
[7] -0.53096986 0.34563279 -0.97023650 -0.94702500 -0.37624883 0.44073439
[13] 0.51851495 -1.93362586 0.74274197 -0.81861024 -0.49963242 1.45553031
[19] -0.47880775 -0.23169624 0.46348261 -1.19764668 0.77737123 -0.50783209
[25] -1.58899290 0.50528381 1.89222336 -0.57809997 0.05806867 1.16785099
[31] -1.06614535 0.61556520 -0.83564718 -1.02615977 0.89271898 0.53811493
[37] -0.54849449 -0.62497474 0.25675859 0.70320768 0.05848728 0.78376690
[43] 0.44276061 -0.58697558 -0.59758547 1.22975543 1.46945195 -0.79496156
[49] -0.58237963 0.16137738 0.22260587 0.45833685 -0.17046269 0.44890726
[55] -0.15563031 0.73221957 -1.97896622 -1.47629166 -2.02214096 -0.96495535
[61] 0.63474420 1.34149420 -0.91755563 0.35488624 0.01262576 -0.34079663
[67] 0.07963539 0.88896173 1.75045613 -0.08678552 0.19245374 1.32575165
[73] 1.41738151 -1.35060833 0.63737697 0.33369705 1.27021960 1.00779108
[79] -1.19586882 0.72829141 -0.09938002 -0.79827963 -1.20575102 -1.09457152
[85] 0.66310803 -0.41086839 -0.50120916 0.02167787 0.60022806 2.94091060
[91] -0.39845012 0.82483674 -2.72699869 -0.48183377 0.57821380 -0.85565220
[97] 2.55905507 0.24447168 0.53042496 -0.31205488

更新于: 07-12-2020

3K+ 查看

开启你的 职业 生涯

完成课程获得认证

开始
广告