I have been learning how to code in R recently, so I\'m not familiarized with apply at all. As far as I know loops are not so efficient in R, so I\'m trying to use apply fun