Re: [R] expanded dataset and random number

From: Muhammad Subianto <msubianto_at_gmail.com>
Date: Thu 22 Jun 2006 - 01:22:03 EST

Dear all,
Per Jensen, thanks for your great help. All methods are very useful.

Best, Muhammad Subianto

On this day 20/06/2006 22:28, Per Jensen wrote:

> A couple of suggestions:
>
> #First solution
> mydatexpanded<-mydat[rep(1:5,mydat[,1]),]
>
> sampledat<-mydatexpanded[sample(1:85,7),-1]
>
> #Second solution
>
> sampledat<-mydat[sample(1:5,size=7,prob=mydat[,1]/85,replace=TRUE),-1]
>
> Regards
> Per Jensen
>
> On 6/20/06, Muhammad Subianto <msubianto@gmail.com> wrote:
>
>>
>> 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
>>
>> ______________________________________________
>> R-help@stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 22 01:36:13 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 22 Jun 2006 - 02:11:54 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.