R newbie here. I am working on a project for which I need to combine multiple years of data into a single summary statistic for each column. For example, I have five years worth of data that need to be averaged, with several columns for different variables. The example provided in modern dive works:
enter code here
summary_monthly_temp <- weather %>%
enter code here
group_by(month) %>%
enter code here
summarize(mean = mean(temp, na.rm = TRUE), std_dev = sd(temp, na.rm = TRUE))
enter code here
summary_monthly_temp
and I modified it to fit my needs:
enter code here
summarysummary<- filename%>%
enter code here
group_by(country) %>%
enter code here
summarize(mean = mean(gdp, na.rm = TRUE),
std_dev = sd(gdp, na.rm = TRUE))
But within the summarize function, I need to summarize a few more variables such as population (getting the mean population) and total gdp.
What is the best way to do this?
I tried something like this but it is not working:
enter code here
summary<- filename%>%
enter code here
group_by(country) %>%
enter code here
summarize(mean = mean(gdp, na.rm = TRUE),
std_dev = sd(gdp, na.rm = TRUE))%>%
enter code here
summarize(mean = mean(pop, na.rm = TRUE),
std_dev = sd(pop, na.rm = TRUE))%>%
I think I know why...piping one function into the other...
Thanks for your input!