# Calculate weighted mean for two columns and hundreds of rows?

I'm trying to teach myself basics of R and I couldn't find the answer:

Say, I have a csv file and I want to calculate weighted mean for each subject such that I have a mean mu = 0.015*1030+0.16*26930+0.24*0+0.87*250+0.29*310+0.77*6240+0.98*3730+0.98*0+0.08*1400 for Subject A, for example.

How would I accomplish it in R or Excel?

Also, if I need to multiply each pair by corresponding value from the same row from the column salary:

0.015*1030*111+0.16*26930*222+0.24*0*333+0.87*250*444+0.29*310*555+0.77*6240*666+0.98*3730*777+0.98*0*888+0.08*1400*999

Thanks UPDATE: mu = sum(df$$Probability * df$$SubjectA * df$salary)  • Thank you! A stupid noob question: how do I create a new row containing mu for all subjects in the existing csv or at least generate a new csv with that data? Thanks! Dec 28 '18 at 10:38 • Assuming you mean a new column containing mu: df$mu = rep(sum(df$Probability * df$SubjectA * df\$salary),nrow(df)) Dec 28 '18 at 11:16