I\'m just starting to learn R language. I spent half a day on trying to write a function and I\'m desperate to find the solution. If someone who is really good could help me