Performance is one of the important topics in the coding field. However, when the program is running during a human's sleeping time, that could be not the priority to focus. Recently I was improving part of my low-performance code in R in order to make running faster, the result is quite satisfied. In this article, you will learn how to rewrite a normal for-loop into SAPPLY function in R.
效能在程式開發中一直是一個重要的議題,但有些程式會是透過排程在半夜運轉的,這時我覺得效能就不一定是最重要的,反而是資料的正確性。近期寫了一個程式來檢核資料是否有遺失,一開始透過迴圈來處理4萬多筆資料時間高達6分鐘,改用R裡的Sapply function來改寫,效能大大提升,而原因在於它只針對單一vector做處理。