Re: [R] Group close numbers in a vector

2011-05-22 Thread Salih Tuna
Hi Jim, I think i sorted it out how to read and write each vector separately. Thanks a lot. It was exactly what i wanted to do. best, salih On Sat, May 21, 2011 at 11:41 PM, jim holtman wrote: > Is this what you are after: > > > x = c(1 ,2 ,4 ,7 ,9 ,10 ,15) > > # partition if the difference is >

Re: [R] Group close numbers in a vector

2011-05-21 Thread Salih Tuna
Yes this is exactly what i want, thanks Jim. One last question, (i am sure this is a very simple question but i am still learning) how can i write the output to a txt file seperately? vector 1 to one file and vector 2 to another and etc? thanks salih On Sat, May 21, 2011 at 11:41 PM, jim holtman

Re: [R] Group close numbers in a vector

2011-05-21 Thread jim holtman
Is this what you are after: > x = c(1 ,2 ,4 ,7 ,9 ,10 ,15) > # partition if the difference is > 2) > breaks <- cumsum(c(0, diff(x) > 2)) > # partition into different lists > split(x, breaks) $`0` [1] 1 2 4 $`1` [1] 7 9 10 $`2` [1] 15 On Sat, May 21, 2011 at 6:03 PM, Salih Tuna wrote: > Hi

Re: [R] Group close numbers in a vector

2011-05-21 Thread Salih Tuna
Hi Robert, thanks for your reply. is there a way to store them in separate vectors? and when i try it with a different example i got different result. For example if x = [1 2 8 9] i want the result to be x1 = [1 2] and x2 = [8 9]. thanks On Sat, May 21, 2011 at 7:16 PM, Robert Baer wrote: > Hi e

Re: [R] Group close numbers in a vector

2011-05-21 Thread Robert Baer
Hi everyone, i am trying to group close numbers in a vector. For example i have a vector x = [1 2 4 7 9 10 15]. I want the code to pick 1 2 4 (max difference between successive numbers is 2) and assign them to variable a, then pick 7 9 10 and assign them to b and 15 to c. But since i do not kno

[R] Group close numbers in a vector

2011-05-21 Thread Salih Tuna
Hi everyone, i am trying to group close numbers in a vector. For example i have a vector x = [1 2 4 7 9 10 15]. I want the code to pick 1 2 4 (max difference between successive numbers is 2) and assign them to variable a, then pick 7 9 10 and assign them to b and 15 to c. But since i do not know ho