Skip to content

Instantly share code, notes, and snippets.

@thistleknot
Last active December 5, 2021 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thistleknot/9739099941f8d2942a99ab21383cbf87 to your computer and use it in GitHub Desktop.
Save thistleknot/9739099941f8d2942a99ab21383cbf87 to your computer and use it in GitHub Desktop.
Create Columns in R on the fly using lapply (functional programming)
Create columns on the fly
combo_s <- do.call(cbind,lapply(1:length(sndif_), function(d)
{
if(sndif_[d]*season == 0)
{
temp <- raw[,d,drop=FALSE]
}else
{
temp <- raw[,d,drop=FALSE]
for(dif in 1:sndif_[d])
{
temp <- temp-dplyr::lag(temp,1*season)
}
}
return(temp)
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment