Create a 100 number vector with random values in R rounded to 2 decimals

I need to do a pretty simple task,but since im not versed in RI don't know exactly how to. I have to create a vector of 100 numbers with random values from 0 to 1 with 2 DECIMAL numbers. I've tried this:

 x2 <- runif(100, 0.0, 1.0)

and it works great, but the numbers have 8 decimal numbers and I need them with only 2.


也许还有:

(sample.int(101,size=100,replace=TRUE)-1)/100

So you want to sample numbers randomly from the set { 0, 1/100, 2/100, ..., 1 }? Then write exactly that in code:

hundredths <- seq(from=0, to=1, by=.01)
sample(hundredths, size=100, replace=TRUE)

要么

x2 <- round( runif(100, -0.005, 1.0049, 2 )
链接地址: http://www.djcxy.com/p/4234.html

上一篇: 如何加入(合并)数据框架(内部,外部,左侧,右侧)?

下一篇: 用R中的随机值创建一个100数字向量,取整为2位小数