Re: [R] How do you test for consecutivity?

2008-04-30 Thread Karl Ove Hufthammer
Charles C. Berry: Are the numbers 1:30 equiprobable?? If so, you can find the probability by direct enumeration. Or by a simple formula: * Probabilities of Consecutive Integers in Lotto * Author(s): Stanley P. Gudder and James N. Hagler * Source: Mathematics Magazine, Vol. 74,

Re: [R] How do you test for consecutivity?

2008-04-29 Thread Marc Schwartz
Anthony28 wrote: I need to use R to model a large number of experiments (say, 1000). Each experiment involves the random selection of 5 numbers (without replacement) from a pool of numbers ranging between 1 and 30. What I need to know is what *proportion* of those experiments contains two or

Re: [R] How do you test for consecutivity?

2008-04-29 Thread Doran, Harold
How about this result - numeric(10) for(i in 1:10){ x - sample(1:30, 5, replace = FALSE) x - sort(x) result[i] - any(diff(x) == 1) } -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Anthony28 Sent: Tuesday, April 29, 2008 8:52 AM To:

Re: [R] How do you test for consecutivity?

2008-04-29 Thread Charles Annis, P.E.
This will work: my.list - c(2, 28, 31, 4, 27) sort(my.list) diff(sort(my.list)) any(diff(sort(my.list)) == 1) the middle two lines are only to illustrate what's going on. Best wishes! Charles Annis, P.E. [EMAIL PROTECTED] phone: 561-352-9699 eFax: 614-455-3265

Re: [R] How do you test for consecutivity?

2008-04-29 Thread Julian Burgos
Hey Anthony, There must be many ways to do this. This is one of them: #First, define a function to calculate the proportion of consecutive numbers in a vector. prop.diff=function(x){ d=diff(sort(x)) prop=(sum(d==1)+1)/length(x) return(prop)} #Note that I am counting both numbers in a

Re: [R] How do you test for consecutivity?

2008-04-29 Thread Charles C. Berry
On Tue, 29 Apr 2008, Anthony28 wrote: I need to use R to model a large number of experiments (say, 1000). Each experiment involves the random selection of 5 numbers (without replacement) from a pool of numbers ranging between 1 and 30. What I need to know is what *proportion* of those

Re: [R] How do you test for consecutivity?

2008-04-29 Thread Julian Burgos
Hey Anthony, My previous function may not work in all cases. Say one of the experiments yields these numbers: 1,2,3,6,7 Would you say that the proportion of consecutive numbers is 100%? If so, this will work: prop.diff=function(x){ d=diff(sort(x)) prop=sum((c(0,d==1)+c(d==1,0))0)

Re: [R] How do you test for consecutivity?

2008-04-29 Thread Anthony28
I'd just like to thank all you guys for stepping in so promptly with help. I haven't yet had a chance to implement any of your code yet, but just by looking over what you've suggested, I think I have enough to guide me. So thanks once again! -- View this message in context: