Generate random sample from gamma distribution

I want to generate a random sample from the gamma distribution data ranges from 1 to 350 in Rstudio. How I can do that?

hi Alhejaili

you may use the following :

mysample <- rgamma(n = 350, shape = 3, scale = 2)

mysample
[1] 6.9043606 11.1916677 1.9280176 3.7493871 8.2891393 5.3837248 4.5008825 3.3753279
[9] 1.7196926 3.4987336 4.3397106 10.4426837 5.5691611 5.3193578 1.2129206 7.4419587
[17] 4.8654486 4.9631310 9.8101134 6.3881587 1.6403636 5.7860577 6.9420557 3.6979280
[25] 6.5751371 11.5928991 15.2806268 11.1989627 17.8224558 9.2924813 5.0787076 11.6483889
[33] 2.4783531 4.6732645 3.3333276 16.2645315 4.6717811 5.8836884 6.7784694 7.9083122
[41] 9.4982322 10.9904380 9.9845215 13.1234904 2.9196424 5.8991554 17.5440942 4.3107736
[49] 6.1640459 2.1502293 6.4714858 3.2162801 3.3374019 2.9854803 2.5793934 3.0806947
[57] 1.0506687 4.9301109 1.9689780 13.1317679 15.0602152 5.1239384 3.2191511 8.8470946
[65] 6.7411636 5.4123474 13.8631905 4.9782904 7.6585954 6.6692173 3.1858892 21.1061955
[73] 4.4077001 13.3593074 4.1632847 4.6810245 4.5363795 5.0909056 13.7606500 1.8071487
[81] 5.4452748 6.2335388 10.0150279 7.5493345 0.6661332 5.4750071 10.5435559 1.4905248
[89] 2.9708874 8.8421752 1.1412383 5.3144472 9.5051481 3.7700321 5.0415353 7.2484712
[97] 3.7693000 3.4224474 1.8672225 4.7864967 10.2098471 3.6824909 3.3323596 4.9545760
[105] 4.2472780 0.8959110 5.4973307 12.6497982 3.5544650 7.2311208 13.6975839 7.1239302
[113] 6.2987295 4.3021929 5.0348278 3.3028129 7.1126025 1.4451030 8.9865328 5.1030671
[121] 7.3780036 1.9424804 6.7547626 6.6261578 2.8433492 5.8879122 7.1970837 2.0278641
[129] 4.2977250 3.4478869 9.1030376 2.8045867 5.6164829 7.5029997 1.1255731 5.9735974
[137] 3.0852275 3.1947088 14.5104204 2.1684114 7.3852641 4.2873973 7.0812001 9.5470571
[145] 8.3220399 2.6664440 1.9196043 10.2832930 6.3362729 8.1278478 1.7711831 6.9703570
[153] 2.7305258 4.6230381 6.0043897 8.3332129 4.6317372 4.1958958 5.1542353 7.9822045
[161] 4.8476723 4.6551989 6.0816210 6.0995698 4.6149027 6.2858133 8.9764838 6.8762959
[169] 3.8927069 5.4021474 5.7377825 6.2270059 4.9498496 8.4496243 2.2695162 5.7924130
[177] 1.2492186 4.2278191 12.6732466 1.0179291 3.1818841 4.3243430 2.4070312 5.1614762
[185] 11.5818275 2.2131395 7.8011125 15.0144837 3.5381998 7.4022810 10.7210281 1.2183439
[193] 9.9579171 9.2187575 6.5821404 4.8777593 7.0232438 6.9817326 5.1326649 7.9480326
[201] 8.0392478 5.9310629 2.2739124 7.5192296 2.7262685 3.5241839 10.7800932 14.9269874
[209] 5.9108781 1.8855199 7.5437596 3.3939828 7.1145032 2.4911249 0.9117698 9.7832399
[217] 1.8949094 3.2791253 5.4969799 4.4796870 4.5366059 6.4397699 4.9694218 6.6135718
[225] 5.3218393 16.0615210 4.9249121 3.8070328 5.1470886 18.4978322 0.7319310 3.4308747
[233] 6.1624300 9.8102674 5.1329788 3.3308892 4.7141756 7.7383492 2.5312070 6.6597397
[241] 2.3650660 3.5999301 3.3275398 8.4558349 1.4926320 14.7761670 2.1591660 16.7562326
[249] 3.0431860 1.5724434 7.9525096 6.5533086 4.7278107 16.6523795 16.4476334 7.8427041
[257] 5.8590617 6.4156672 13.7072309 5.0649708 12.0762846 2.8325286 8.9686715 1.9951146
[265] 3.5661079 9.0991859 6.5118695 10.5102433 5.4259266 3.8637826 5.7159960 5.6033711
[273] 6.0525582 5.9148247 1.9307588 3.9127649 2.4127314 13.7892516 3.2559675 4.8592175
[281] 7.9659559 3.8541674 3.9917817 13.3104987 8.0383867 10.0723776 2.2316542 2.1578945
[289] 7.5911565 6.0382352 4.9699162 4.8825693 10.3409134 3.7709032 4.7488293 7.4116045
[297] 4.5612205 3.1537456 9.8922704 4.5651850 5.3680393 1.7539070 6.0384334 6.2346614
[305] 5.1495758 2.3268363 4.2895050 5.6121312 6.0889159 4.0017591 0.8284140 5.2041860
[313] 7.2771198 4.1174949 8.5440022 14.2233045 5.4148430 5.8269394 4.3085008 10.0590745
[321] 7.3508111 7.6430174 9.7173322 4.0752015 6.2870337 7.0160900 12.9686841 7.9606172
[329] 5.4189731 4.9987401 6.6300082 6.9669353 5.7908355 4.8669094 7.6600528 3.2792572
[337] 5.8252833 3.0123078 3.5506953 7.8172222 3.7152832 4.9403861 2.6350826 9.0883931
[345] 4.5262904 6.0397974 6.8525144 5.1586512 2.6386994 3.1809305

Kind Regards

I want the maximum number in the sample 350 not the sample size 350.

Just remove the numbers that you don't want.
So if you need 100 numbers generate e.g. 110 numbers and then select the first 100
(and check that the result has a length of 100).

But if you remove numbers over 350 your numbers will no longer be distributed exactly gamma, since the gamma distribution doesn't have a limit. Nothing wrong with that, if that's what you want.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.