Final version of dvapply()