How To Calculate Conditional Mean In R