How to generate a random number in R

Generate a random number between 5.0 and 7.5
x1 <- runif(1, 5.0, 7.5) # 参数1表示产生一个随机数
x2 <- runif(10, 5.0, 7.5)# 参数10表示产生10个随机数

Generate a random integer between 1 and 10
x3 <- sample(1:10, 1)  # 参数1表示产生一个随机数
x4 <- sample(1:10, 5, replace=T) # 参数5表示产生5个随机数, 参数replace=T表示数字可以重复出现(类似于放回抽样)

Select 6 random numbers between 1 and 40, without replacement
x5 <- sample(1:40, 6, replace=F)# 参数6表示产生6个随机数, 参数replace=F表示数字不可以重复出现(类似于不放回抽样)

Select 10 items from a list of 50
sample(state.name, 10)
sample(state.name, 52)
sample(state.name, 50)

REF:

http://www.inside-r.org/howto/how-generate-random-number-r

时间: 2024-12-13 04:18:26

How to generate a random number in R的相关文章

zenefits oa - random(5) to generate a random(7)

If given a function that generates a random number from 1 to 5, how do you use this function to generate a random number from 1 to 7 with the same probability? (ie. function a has probability 1/5 per number, function b would have probability 1/7). in

Linux shell get random number

the Shell Profile: When a new interactive shell is started, /etc/profile, followed by /etc/bash.bashrc(if a bash shell), ~/.profile, and finally ~/.bashrc are executed in that order. PATH You can set your PATHenvironment variable to tell the shell wh

LoadRunner压力测试之Unique Number参数类型、Random Number参数类型浅析

前几天工作需要用LoadRunner进行压力测试,期间对手机号进行参数化设置. 当时选用了<Value>137{Random_quhao}{Unique_weiyi}</Value>模式,Random Number.Unque Number参数类型选择如下: Parameter type Random Number Unique Number Number(Block size per) 9999 9999 Sample 0001 0001 Number %04lu %04d Up

C++ 利用&lt;cstdlib&gt; 头文件 , 产生一个random number generator

头文件<cstdlib>中有一个重要的函数 rand() , 可以作为随机数发生器. 现在现在我想产生一个随机数, 我使用如下的程序: #include <iostream> #include <ctsdlib> <span style="font-family: Arial, Helvetica, sans-serif;">using namespace std;</span> int main() {     cout &

C# random(number)

C#随机函数Random()的用法 出自:http://www.cnblogs.com/wang726zq/archive/2012/04/28/2474711.html http://blog.csdn.net/xianxianmohan/article/details/6587909 http://www.cnblogs.com/falla/archive/2010/01/29/1659399.html http://blog.csdn.net/pfe_nova/article/detail

generate alphanumeric serial number

generate alphanumeric serial number with the following BADI / Customer Exit: Name of Enhancement : IQSM0001 Name of Function Module Exit: EXIT_SAPLIPW1_001 Name of Include : ZXQSMU01 ZXQSMU01: This user exit can be used to create the serial numbers a

@codechef - [email&#160;protected] Random Number Generator

目录 @[email protected] @[email protected] @part - [email protected] @part - [email protected] @part - [email protected] @accepted [email protected] @[email protected] @[email protected] 给定递推关系式:\[A_i=C_1A_{i-1} + C_2A_{i-2}+\dots+C_kA_{i-k}\] 并给定 \(A_

Linux Apache2.4 AH00141: Could not initialize random number generator

检查编译安装步骤,如果是采用下面这个方法安装,请换一种方法,我遇到过多次这个问题,都是因为这个安装问题导致的. 存在问题的方法 解压apr apr-util,去掉版本号,拷贝至httpd-<version>/srclib/ ./configure --prefix=/usr/local/apache2 --enable-dav --enable-so --enable-mods-shared=all --with-egd --with-devrandom --enable-so --enabl

如何用R产生一个随机数

转载自   如何用R产生一个随机数 如何选择一个随机数在R As a language for statistical analysis, R has a comprehensive library of functions for generating random numbers from various statistical distributions.作为一种语言进行统计分析,R有一个随机数生成各种统计分布功能的综合性图书馆. In this post, I want to focus