Follow up PR: #28097 Simplify branch statement

xref #28097

This is follow up pr. eliminate branch statement. "grouper" variable is assigned  when handle NAs.
can you merge master and see if you can get passing thanks @proost this is not exactly what I was looking for, but its ok. thanks. @MeeseeksDev backport to 1.0.x