Generate a set of random unique integers from an interval

后端 未结 3 1583
离开以前
离开以前 2021-02-03 21:31

I am trying to build some machine learning models,

so i need a training data and a validation data

so suppose I have N number of examples, I want to select rando

3条回答
  •  旧时难觅i
    2021-02-03 22:03

    sample (or sample.int) does this:

    sample.int(100, 10)
    # [1] 58 83 54 68 53  4 71 11 75 90
    

    will generate ten random numbers from the range 1–100. You probably want replace = TRUE, which samples with replacing:

    sample.int(20, 10, replace = TRUE)
    # [1] 10  2 11 13  9  9  3 13  3 17
    

    More generally, sample samples n observations from a vector of arbitrary values.

提交回复
热议问题