I have 19 rows worth of data with columns A and B which looks like this:

A B
0 6.5
1 6.4
2 6.3
3 6.1
4 6.0
... ...

If, for example, I wanted to combine rows A=0,1 and rows A=2,3,4, with column B taking the mean of the joint rows, how would I code this? I've tried using aggregate(), but am not sure how to combine the specific rows when they don't share a common value.

This is really helpful, thank you!
With the data I'm using, I actually want to group the rows such that A=0, A=1, A=2-4, A>5 are separate rows (so there are 4 rows altogether). I tried using your code and adjusting it to try to do this, but am not sure how to type A=2-4 as code..