Brilliant answer in StackOverflow on improving code performance in R | Dark Hacker News