Corrected coalesce issue

ifelse was acting strangely, and forcing the aggregation to use ints
with NA_integer_ also appeared to help.