[R] Discover significant change in sorted vector

Hans-Henning Gabriel hanshenning.gabriel at gmail.com
Wed Apr 22 14:06:01 CEST 2009


> Hans-Henning Gabriel wrote:
>> Hi,
>>
>> suppose I have a simple sorted vector like this:
>>
>> a <- c(2,3,3,5,6,8,8,9,15, 25, 34,36,36,38,41,43,44,44,46);
>>
>> Is there a function in R, I can use to discover that from index 8  
>> to index 11 the values are changing significantly?
>> The function should return a value pointing to one of the indices  
>> 8, 9, 10 or 11. Any of them would be fine.
>> The difficulty is that there may be no big gap. I mean, indices 8  
>> and 11 are somehow "connected" by indices 9 and 10. So, it's not an  
>> option to just search for biggest difference between the values.
>>
>> Perfect would be a function that is able to discover multiple  
>> changes if it is present in the data.
>>
> Hi Henning,
> Is max(diff(a)) any good to you?
>
> Jim
>

Hi Jim,

no, I'm affraid it's not. It's more like that the slope is low for  
many values, then it starts getting stronger for few values, then it  
gets low again for many values. But the thing is that the slope may  
_not_ change immediately.

Henning




More information about the R-help mailing list