0

I would like to know how to implement a way to get a random sub-sample within a larger sample in R using a large collection of true random numbers (obtained using a quantum generator) those are integers which can have multiple occurrences.

__

Edit: Solution.

Since I needed a remise and my generated numbers in a float64 were finally unique (due to the high precision), I have used the following solution :

1) generate as many numbers as length(data)

2)

temp<-cbind(data,randomnb)
randomizeddata<-res[order(res[,2])]

3) split the dataset

4

3 回答 3

6

For true random numbers, use randomNumbers from the random package.

r <- randomNumbers(number_of_samples, max = nrow(your_data), col = 1)
your_data[r, ]
于 2011-07-20T17:05:50.950 回答
1

Let's say v is your data and r are the true random numbers (scaled so that they range from 0 to 1):

> v <- runif(100)
> r <- runif(10) # using psedo-random numbers for demo purposes
> v[r * length(v) + 1]

This selects ten random elements from v (with replacement).

于 2011-07-20T17:06:21.693 回答
0

What about sample function ?

e.g.

set.seed(3) # just to get the same result
x <- 1:10
sample(x,10)
# print: 2  8  4  3  9  6  1  5 10  7
于 2011-07-20T16:57:46.873 回答