Select random element in a list of R?

后端 未结 6 1191
太阳男子
太阳男子 2020-12-29 19:19
a<-c(1,2,0,7,5)

Some languages have a picker -function -- choose one random number from a -- how in R?

6条回答
  •  生来不讨喜
    2020-12-29 19:56

    Read this article about generating random numbers in R.

    http://blog.revolutionanalytics.com/2009/02/how-to-choose-a-random-number-in-r.html

    You can use sample in this case

    sample(a, 1)
    

    Second attribute is showing that you want to get only one random number. To generate number between some range runif function is useful.

提交回复
热议问题