marcfandetti.bsky.social
@marcfandetti.bsky.social
Seeking hair-loss cure using TSLS.
June 9, 2025 at 9:33 PM
Embarrassed that I just discovered this "shortcut" for calculating rolling autocorr in R using slide_dbl.

Steps:

1) create function

auto_corr -> function(x) { cor(x, lag(x, 1), use = "complete.obs" }

2) assign function to .f in slide_dbl

That's it.

Way shorter than a for loop.

#rstats
December 7, 2024 at 9:25 PM
Embarrassed that I just discovered this "shortcut" for calculating rolling autocorr in R using slide_dbl.

Steps:

1) create function

auto_corr -> function(x) { cor(x, lag(x, 1), use = "complete.obs" }

2) assign function to .f in slide_dbl

That's it.

Way shorter than a for loop.

#EconSky
December 7, 2024 at 8:25 PM