首页 > 代码库 > R语言-rnorm函数

R语言-rnorm函数

rnorm()函数产生一系列的随机数,随机数个数,均值和标准差都可以设定。

1 > x<-rnorm(100)       #产生100个服从正态分布的随机数2 > print(x)
 [1] -0.26324109  0.10288996 -0.19853384 [4]  0.20795624 -0.67943297  1.10336811 [7]  0.27014386 -0.22539815  0.21058139 [10] -0.08845235  0.57193731  0.38441138 [13] -0.16234544 -1.05885749 -0.31676977 [16]  0.09160984  0.85869406 -1.92437870 [19]  0.13930256 -0.38939669 -1.30904417 [22] -1.64585501 -1.10237222 -0.78996995 [25] -0.08953180 -0.57261995  0.75944219 [28] -0.27586470  0.22038731  1.07290135 [31]  1.31221548 -1.17559017  0.44867447 [34]  0.92308930  0.28249317  0.03514011 [37] -0.49339015 -0.97298188  1.64675994 [40]  0.05560634  0.21019148  0.46795645 [43]  0.93547472  1.24787602 -0.70754604 [46] -0.53861572  1.11944711  0.68947881 [49] -0.23630802 -1.28280493 -0.70265838 [52] -0.42406630  1.56637981  0.36190251 [55]  1.60644945  0.77273024 -1.28584961 [58] -1.20758388  0.76275871  0.28845264 [61] -0.92902203  0.17398453 -0.13379084 [64]  2.19181951 -0.02141348 -0.98340831 [67] -0.98250819  0.78877798  1.31430210 [70] -1.58568841 -0.02860521 -0.03645140 [73] -0.20290850  0.21163409  0.44485326 [76]  0.75211751  0.97126478  1.55586721 [79] -1.16956405 -1.22934317 -0.16197414 [82]  0.26927615  1.79530684 -0.50801284 [85]  1.39475512 -2.44997555  0.12599863 [88]  0.34823393  0.38774490  0.99990464 [91]  0.36716384  1.99150108 -0.38290675 [94]  0.60751652  0.09480957 -0.20563194 [97]  1.71996544  0.06382987  0.19579251[100] -0.10073099

技术分享

1 > x<-rnorm(100,3,4)       #产生100个均值是3,标准差为4的随机数2 > print(x)
 [1]  1.49656925 11.95936490  6.88970327 [4]  0.40415294  5.86416522  0.63424442 [7]  0.48301686 -0.11507020  2.78108833 [10]  6.34683598  0.41899008  4.30549109 [13]  0.05657324  9.09961354  0.50791366 [16]  9.37733170  4.48574351 -0.89857176 [19]  1.12643236  3.93898234  0.17518864 [22] -3.54634182 -4.70234252  9.82584151 [25] -1.05972911  5.81132397  8.65915568 [28] -4.70963922  4.05207848  3.86882175 [31]  3.25272474  1.64543632 -0.63657621 [34] -3.19041652 10.93314413 -0.60856151 [37]  0.47559227  8.49264500  8.93107758 [40]  0.37652898  8.30558795  5.53069155 [43]  0.68242390  4.92089359 -0.42385840 [46]  1.84038254  4.92277540  6.82399382 [49] -0.50417642  6.74601180  1.36258799 [52]  9.96709281 -3.07820065  3.10318421 [55]  3.54411733  8.52122244  0.88853265 [58]  8.57470109 -2.14551460 -0.50774596 [61]  2.84178486  3.15692093  6.10531593 [64] -0.43015779  0.06777219  7.47884137 [67]  1.72870486  7.54601723  5.40613275 [70]  5.36976037  7.36394231  1.27398026 [73]  6.32744407  9.50486546 -3.33475582 [76]  4.55947536  3.14531065  1.26117393 [79]  7.78038761  2.24518204  3.10945300 [82] -0.13109504 -6.57291074  9.51343571 [85] -2.14250267  2.60657651 12.42863819 [88]  1.50207810  4.69823542  5.07431396 [91] -0.47208321  2.71782519 -0.04013664 [94]  3.91216269  3.40533228  6.13103940 [97]  0.29818172  6.49477693  3.76956111[100]  4.10297196

技术分享

R语言-rnorm函数