fixed DF merge and used "cast" to calculate mean