changed library(ddply) to library(dplyr)