Code for comparing X with Y?

R doesn't have a 'box' concept. I would seem to be free to interpret this in any number of ways, and then you would only benefit from my solution, if your data resembled it sufficiently.
Why guess. If you have data structured in some particular way, please share a sample of the data for the avoidance of doubt and misunderstandings.