It's totally ok, you're not expected to know the rules. And I'd be really happy to help you, but two things first:
- Please put this in the format of a reproducible example ("reprex") so that it's clear exactly what you're asking. Right now I'm not sure if, for example, your table is in the form a data frame, data table, or matrix. I'm also not sure if there are any constraints on your task. Does it need to be vectorized or would a for loop be ok (there's a hint, if you want it).
- It's important for all of us who code in any language that we learn how to solve problems and get unstuck on our own. Please show us what attempts you've made to solve this problem and then we can help you from there.
Good luck