Skip to content

Instantly share code, notes, and snippets.

View romans127's full-sized avatar
πŸ’­
Engineering Stuff

Ryan Watts romans127

πŸ’­
Engineering Stuff
View GitHub Profile
@romans127
romans127 / Avoiding a loop.R
Created October 23, 2017 18:05 — forked from dsparks/Avoiding a loop.R
lapply() as an alternative to a multiply-nested loop
# Alternative to a doubly-nested loop
# Imagine I want to perform an operation on a data frame
# once for each combination of two variables, such as Country and Year
# I can do this with a nested loop, or I can do this with (among other
# things) lapply()
# Generate random data:
allCountries <- LETTERS[1:10]
allYears <- 1990:2012
@romans127
romans127 / Avoiding a loop.R
Created October 23, 2017 18:05 — forked from dsparks/Avoiding a loop.R
lapply() as an alternative to a multiply-nested loop
# Alternative to a doubly-nested loop
# Imagine I want to perform an operation on a data frame
# once for each combination of two variables, such as Country and Year
# I can do this with a nested loop, or I can do this with (among other
# things) lapply()
# Generate random data:
allCountries <- LETTERS[1:10]
allYears <- 1990:2012