jeudi 8 juin 2017

Generate number of random sample of specified length in R

I think it's my poor knowledge of R, especially poor knowledge of loop-related codes.

Here is what I am trying to do. Assuming I have numbers from 1 to 500. first, generate 300 sets of two randomly picked numbers from 1 to 500, assign to each set a number from 1 to 300, and then combine them into one dataset, let it be dataset A.

So A will look like

A_no  random_num
1       26
1       256
2       3
2      113
...

Then I need to create a dataset B where I will have sets of 3 random numbers out of 500, also counted

B_no  random_num
1       16
1       113
1       4
2       67
2       25
2       7

I believe the R code will look very elegant and simple. Will really appreciate any help with this solution.




Aucun commentaire:

Enregistrer un commentaire