# Calculate an average after deleting points that satisfy a condition

I want to calculate an average where points that fall under a specified area are omitted.

I have tried using DeleteCases and If, but have had no luck so far.

This is the code I have so far:

(*data*)
countries = CountryData["Countries"];
fem = (Map[CountryData[#, "FemaleLifeExpectancy"] &, countries] //
DeleteMissing // QuantityMagnitude);
male = (Map[CountryData[#, "MaleLifeExpectancy"] &, countries] //
DeleteMissing // QuantityMagnitude);
pts = Transpose[{fem, male}];

(*desired area*)

pol = Polygon[{{55, 60}, {60, 70}, {70, 55}, {60, 50}}];
rm = RegionMember[pol];

DeleteCases[rm[pts], True];


p1 = ListPlot[pts, Prolog -> {Lighter@Cyan, pol}];
pts2 = Pick[pts, Not /@ (RegionMember[pol] /@ pts)];
p2 = ListPlot[pts2, PlotStyle -> Red
, Prolog -> {Lighter@Cyan, pol}];
GraphicsRow[{p1, p2}]


m = Mean[pts2];
ListPlot[pts2
, Epilog -> {
Red, AbsolutePointSize[6], Point@m
}
]

• What would be a way to calculate the average for females and males separately? Commented Feb 5, 2022 at 12:55
• First@m and Last@m ? or explicitly as Mean[pts2[[All, 1]]] etc.
– Syed
Commented Feb 5, 2022 at 12:56