[R] Near function?

Dimitris Rizopoulos Dimitris.Rizopoulos at med.kuleuven.be
Sun Feb 11 10:17:34 CET 2007


maybe you could try something along these lines:

x <- c(1, 3, 2, 5, 11)
thr <- 3
###
ind <- t(combn(x, 2))
unique(c(ind[abs(ind[, 1] - ind[, 2]) <= thr, ]))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
      http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Bart Joosen <Bartjoosen at hotmail.com>:

> All,
>
> thanks for your help.
>
> Dieter,
>
> thanks, it's a different way of tackling the problem.
> But I still need a for loop to scroll throug the list?
>
> For example:
> c(1,2,3,5,)
> and a threshold of 3, then c(1,5) should remain. If I make an   
> integer with the difference between each element and the previous   
> element,
> then 5 should be eliminated, while it shouldn't.
>
> Or am I wrong with this assumption?
>
> Thanks anyway
>
> Bart
>
>
>>
>> Hi,
>>
>> I have an integer which is extracted from a dataframe, which is sorted by
> another column of the dataframe.
>> Now I would like to remove some elements of the integer, which are near to
> others by their value. For example:
>> integer: c(1,20,2,21) should be c(1,20).
>
> ...
>> Sorting the integer is not an option, the order is important.
>
> Why not? It's extremely efficient for large series and the only method that
> would work with large array. The idea: Keep the indexes of the sort   
> order, mark
> the "near others" for example making their index NA, and restore   
> original order.
> No for-loop needed.
>
> Dieter
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>
>



Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list