
Jesse E. answered 05/26/19
Tutor
4.6
(8)
Experienced tutor for TEAS, chemistry, and biology
Take the following as an example. Suppose you want the following:
The year is [year] where [year] is equal to 2010, 2011, up to 2015.
The code for this would be as follows:
for (year in c(2010,2011,2012,2013,2014,2015)){
print(paste("The year is", year))
}
"The year is 2010"
"The year is 2011"
"The year is 2012"
"The year is 2013"
"The year is 2014"
"The year is 2015"

Jesse E.
Follow this link for more information: https://www.r-bloggers.com/how-to-write-the-first-for-loop-in-r/05/26/19