NHL 2016-2017 Data to determine Avg amount of Goals for a played position.

I am trying to filter positions to C, R, L, and D. I want to calculate the avg number of goals based on Pos from this list. I am having a tough time filtering the positions and ultimately use averages or medians of data to associate a given position. I would also like to find the proportions of position amongst the top scorers in the league which could help with strategy as well.

Thanks

Welcome aboard.

I think we need a FAQ: How to do a minimal reproducible example ( reprex ) for beginners

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need.

The following uses mtcars data, but hopefully will be helpful:

library(dplyr)
df <- data.frame(mtcars)
df %>%
filter(cyl == c(4,6)) %>%
group_by(cyl) %>%
summarize(mean_mpg = mean(mpg), median_mpg = median(mpg))
df %>%
arrange(desc(mpg))%>%
head(20) %>%
group_by(cyl) %>%
summarize(n = n()) %>%
mutate(proportions = n / sum(n))

A tibble: 2 x 3

cyl mean_mpg median_mpg


1 4 24.7 22.8
2 6 19.9 19.7
summarise() ungrouping output (override with .groups argument)

A tibble: 3 x 3

cyl     n proportions


1 4 11 0.55
2 6 7 0.35
3 8 2 0.1

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.