support NaN values in numeric grouping variables in dummyvar. - #481
AvanishSalunke wants to merge 1 commit into
Conversation
|
The inconsistency you are closing is real. The categorical branch has filled NaN rows for I checked the behaviour against MATLAB R2024a. The per variable rule is correct. Your test on The cell array and the row vector agree as well, so that test and the sentence you added to the help text both stand. A grouping variable that is entirely NaN needs handling. On MATLAB does not raise there. The variable contributes no columns and the caller is warned, so K = max (g, [], 1, 'omitnan');
allnan = find (isnan (K));
if (! isempty (allnan))
warning (strcat ("dummyvar: the following grouping variables contain", ...
" only NaN values and produce no dummy variables:", ...
" %s."), mat2str (allnan));
K(allnan) = 0;
endif
D = zeros (nr, sum (K));Please add a test for it. Save and restore the warning state the way the blocks in Three smaller points:
One last thing, which is not yours and needs no change here. |
a NaN in group would just throw a error instead of producing a NaN row. Fixed it by letting NaN through validation and filling NaN across that grouping variable's own block of dummy columns for affected rows.
BEFORE:
AFTER:
MATLAB: