Use dplyr to deal with "by" argument