Hello,
I have a column A (around 15,000 rows) which has numbers and many null values (maybe 70-80% null).
I would like to construct a column B which at row i, is equal to the the mean of: the *last 10 non-null values from A*
--> this means take A[row i-1] , A[row i-2], ... and go back until you have 10 non-null values (or if you reach row 1 then take whatever number <= 10 of non-null values you get)
I would also like to do in addition to mean, a median and also mode, but a smoothed version of the mode where:
I first do a Gaussian smoothing of the 10 non-null values ... and take the argmax (mode) of that distributions.
Thanks for any thoughts or suggestions!
***
Solution ideas: One thought I had was because I want to do several different calculations with the last 10 non-null values, I should first construct a column C whose entries are arrays equal to those last 10 non-null values ... then I can do 3 formulas which operate on column C to produce B1 (mean), B2 (medial), B3 (smoothed mode).
Here are some code fragments moving towards constructing this column C of arrays:
//step 1 grab the last say 50 entries (some fixed amount that will likely have 10 non-nulls)
For Each Row( dt_join,
to = Row();
If( to - 50 < 0,
from = 1,
from = to - 50); // Quantile( 0.5,
values = :away_1g_pull_seconds[Index( From, To )] <<Get Values //this is an array
Show(values);
If(Row() > 50, Break());
);
//step 2 convert array to list, drop nulls, convert list of first 10 entries back to array ...
//I don't know how to assign this to a row of C
num_lag = 10;
values = dt_join:A[Index( From, To )] ;
MyList = Remove(as list(values)[1], as list(Loc(as list(values)[1], .)) ); //convert array to list and remove nulls
Mat = Number Col Box("", MyList[1:10]) << get as matrix; //hack convert to array