Calculating the averages in bins

Hi I want to calculate the average of the data in bins. Assume that:
bin width = 4 ( for every x values)
x , y
2, 3
2, 2
5, 5
7, 2

The output should be the averages of the y numbers: ( output = (3+2)/2 , (5+2)/2)

Thanks in advance

Hi @regulus! Welcome!

Can you please try turning your question into a reproducible example (follow the link for instructions and explanations). You should include any code you’ve already tried, even if it doesn’t work.

Without a reproducible example, I’m afraid a question like this sometimes comes across as impolite: as though the asker is expecting other people to write their code for free. Certainly you are asking a helper to at least write some code to construct a sample data frame before they can get started on your puzzle. Instead, I think that if you set it all up nicely for your helpers and show the dead ends you’ve already found, you’ll be much more likely to attract interested people to your problem.

1 Like