I have the following code which takes eternity to perform on my data set. I could not find a function out of an existing package so I wrote the function myself. The task is to c