I am looking to determine the max score within a data set but only when looking the group population is above a certain threshold, in this case above 20. sample data:
Race = c("African American", "Asian", "Hispanic", "White")
Population = c(28, 11, 31, 64)
Average_Score = c(65, 82, 49, 75)
df = data.frame(Race, Population, Average_Score)
Race Population Average_Score
1 African American 28 65
2 Asian 11 82
3 Hispanic 31 49
4 White 64 75
What I would like to do is something like:
df %>% mutate(reference=max(Average_Score)) where Population > 20
however, I need to add a condition so that it only pulls the max(Average_Score) where Population is greater than 20. In this case, instead of returning Average_Score of 82 (because the Asian population is less than 20) it would return Average_Score of 75 (because the highest Average_Score of any group with Population greater than 20 is the Average_Score that coincides with White)
Any help would be greatly appreciated.
max(Average_Score[Population > 20])