I am trying to write a function to iterate over two variables (i.e. region and event). However, sometimes I need to apply the function to analyse the data of each whole region without dividing it into events.
I wrote the following code:
myfunction <- function(a, b, c, events_included = FALSE){
for(region in c("A1", "A2", "A3", "A4")){
for (event in 1:30){
# The main code (tweaked to deal with the both cases in
# which events_included = FALSE and TRUE).
}
}
}
I wonder if there is a way to deactivate the second loop (i.e. event) if the variable events_included = FALSE
.