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