adding timelag function into R file