Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How do I create a summary statistic for multiple years and variables?

$
0
0

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 heresummary_monthly_temp <- weather %>% enter code heregroup_by(month) %>% enter code heresummarize(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 heresummarysummary<- filename%>% enter code heregroup_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 heregroup_by(country) %>% enter code heresummarize(mean = mean(gdp, na.rm = TRUE), std_dev = sd(gdp, na.rm = TRUE))%>% enter code heresummarize(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!


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>