The best fill code depends on the size of the data arrays and the density of
missing elements but after some experimentation over 10<n<1e6 and missing
percentages from 50 down to 1 the two simple steps
m =: I. a: = data
(<"0 m{fill) m}data
seem to perform faster than Dan's
(data=a:)}data ,: <"0 fill
and by a factor of at least 2 for the other suggestions.
In many problems the appropriate missing value is only calculated for
missing cases simplifying the expression even further.
Fraser
----- Original Message -----
From: "Raul Miller" <[email protected]>
To: "Programming forum" <[email protected]>
Sent: Friday, August 14, 2009 1:14 AM
Subject: Re: [Jprogramming] filling in missing values
On Thu, Aug 13, 2009 at 7:49 AM, John
Randall<[email protected]> wrote:
> Dan Bron wrote:
>>> Suppose I have some data, and some default values to
>>> use in case there is no data:
>>> data =. a:,(1;2;3),a:,(3;2)
>>> fill =. 10 20 30 40 50 60 70
>>> The result I want is:
>>> 10;1;2;3;50;3;2
>>
>> I prefer the mask}data,:fill idiom:
>>
>> (10;1;2;3;50;3;2) -: (data=a:)}data ,: <"0 fill
.....
>
> And I like the selection vector approach: sv {"_1 x,.y .
>
> (10;1;2;3;50;3;2)-:(data=a:) {"_1 data,.<"0 fill
.....
And I prefer the arithmetic approach
(10;1;2;3;50;3;2) -: <"0 ({.&> data) + fill * data=a:
1
--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm