[Jprogramming] replacing missing values with closest neighbor

Raul Miller rauldmiller at gmail.com
Thu Sep 29 18:18:22 HKT 2011


On Wed, Sep 28, 2011 at 10:44 PM, Lettow, Kenneth <KLettow at thomasnet.com> wrote:
>   sa=: 1 2 5 9
...
>   NB. nearest value in sa.  The desired result should be:
>   desiredresult=: 1 1 2 2 5 5 5 5 9 9

Here's a brute force approach:

   ({."1 {~ |: i."_1 <./)@:|@(-/ 1 i. at + >./) 1 2 5 9
1 1 2 2 5 5 5 5 9 9

-- 
Raul


More information about the Programming mailing list