[R] expanded dataset and random number

Muhammad Subianto msubianto at gmail.com
Tue Jun 20 13:10:29 CEST 2006


Dear all R-users,
(My apologies if this subject is wrong)
I have dataset:
mydat <- as.data.frame(
         matrix(c(14,0,1,0,1,1,
                  25,1,1,0,1,1,
                  5,0,0,1,1,0,
                  31,1,1,1,1,1,
                  10,0,0,0,0,1),
         nrow=5,ncol=6,byrow=TRUE))
dimnames(mydat)[[2]] <-c("size","A","B","C","D","E")
> mydat
  size A B C D E
1   14 0 1 0 1 1
2   25 1 1 0 1 1
3    5 0 0 1 1 0
4   31 1 1 1 1 1
5   10 0 0 0 0 1
> sum(mydat$size)
[1] 85
>

where size is number of each row that have this combination of variables.
In this dataset I have 85 tuples in expanded dataset.
I want to generate random number between 1 and 85.
Say, if the first random number is 15, so the number 15 is
1 1 0 1 1
then, if the next random number is 7, then
0 1 0 1 1

then if
random number is 79
0 0 0 0 1
random number is 46
1 1 1 1 1
random number is 3
0 1 0 1 1
random number is 28
1 1 0 1 1

So, the result random tuples (order from 6 random number):
0 1 0 1 1
0 1 0 1 1
1 1 0 1 1
1 1 0 1 1
1 1 1 1 1
0 0 0 0 1

I  would be very happy if anyone could help me.
Thank you very much in advance.
Kindly regards,  Muhammad Subianto



More information about the R-help mailing list