I need to do a pretty simple task,but since im not versed in R I 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.
For uniformly distributed (flat) random numbers, use runif() . By default, its range is from 0 to 1. To generate numbers from a normal distribution, use rnorm() . By default the mean is 0 and the standard deviation is 1.
Perhaps also:
(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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With