Philip A. Viton wrote: > Thanks, Roger (and also for the reminder that _ % _ is NaN : it must > have been another edge-case that I was thinking of). > > Anyway, maybe I'm missing something, but how would one implement the > boolean suggestion when one was going to do, eg v (+/ . * ) mx where v > is a vector and mx is a matrix (ie the matrix product of v and m)? > Wouldn't this require you to do all calculations twice, once with the > data and one for the boolean control?
I find that negative infinity for NA works pretty well, assuming that this value cannot arise in normal calculations. You do need cover functions for each operation, and this runs an order of magnitude slower. You can still use array processing - the cover functions need not be element-by-element. This is not much different from Roger's suggestion, since the boolean is simply NA ~: data. The main problem is that the exact behaviour of NA depends on each calculation, e.g. ignore it, treat it as 0, carry it forward etc. In complex calculations, the required behaviour may not be obvious. R does support NA and calculations default to return NA when present, which is nice. But if you want non-default behaviour you need to specify it in each call, or use cover functions. I suspect that other than simple cases, much the same problems arise in R as in J. I put up a script with example definitions at http://www.jsoftware.com/jwiki/Scripts/Missing_Values . ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
