Use of dplyr instead of ave() and ddply() almost reduces the computing time by 50%! Works fine!