# Calculating Mean of multiple variables in R

Hi everyone, I have to complete a problem set for a data science course I am enrolled in, and I am having a difficult time figuring out the code for calculating the mean of more than one variable.

here is what I have so far

``````library(tidyverse)
library(dplyr)
names(df)
summary(df)
df\$vote_D
dem_pct <- 100*df\$vote_D/(df\$vote_D+df\$vote_R)
mean(dem_pct)
``````

I need to calculate the mean of dem_pct in which a Democratic incumbent, Republican incumbent is running, and when neither party has an incumbent running. The variables for these in the program are df\$inc_D and df\$inc_R. I understand this is a simple procedure, but I have had a difficult time finding the correct keywords for this search.

Thank you!

``````mean(df\$inc_D)
mean(df\$inc_R)``````

Thank you, but I need to find the mean of dem_pct when a Rep incumbent is running, a Dem incumbent is running and when neither has a candidate running. It seems that code wouldn’t take into consideration the dem_pct variable I created?

oh, at this point we probably would need to see at least a sample of the data.
can you share it ?
dput() function

I'm honestly having a hard time doing that function, I could send you the .csv file?

I would like to learn how to do that so if theres a way you can help me out with doing dput() function that'd be great.

If you want to learn how to properly ask questions here by providing a reproducible example (reprex) illustrating your issue.

Please have a look at this guide, to learn how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.