Loop through list in R

Option 1:

testList <- list(22, 34, 15, 47, 13)
 
# loop version 1
for (num in testList) {
  print(num)
}

Option 2:

testList <- list(22, 34, 15, 47, 13)
 
for (i in 1:length(testList)) {
  print(testList[[i]])
}
Content Protection by DMCA.com
Please Share