[R] Near function?

Dieter Menne dieter.menne at menne-biomed.de
Sat Feb 10 11:38:06 CET 2007


Bart Joosen <bartjoosen <at> hotmail.com> writes:

> 
> 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



More information about the R-help mailing list