Binning coordinates (lat and long) into boxes, and performing analysis of other measurements within those boxes

I have a dataset that is 600 points, consisting of latitude, longitude, and 25 chemical species measured at each point. I'm trying to bin them into spatial boxes that are 1 degree x 1 detgree, then calculate the average of each chemical species within each box.

I'm aware of the histogram function, but I'm not sure if it is what I'm looking for here.

I tried writing functions that would bin for me, then I could export to excel and just perform the analysis on each bin manually, but I was having problems with indexing. Excuse me, I'm still very new to writing code:

function bin(latitude, longitude, box)
wave latitude, longitude, box
if (latitude>39 & latitude<40 & longitude>270 & longitude<271)
box=1
endif
end


Any help would be greatly appreciated - I'm sure this is a common type of analysis, but I'm just not sure how to do it in Igor. Thank you!
I figured out a good way - the Findpointsinpoly function is really helpful, then I just used the extract function to pull out the values for each box.