Skip to content
Prev 175038 / 398506 Next

programming creating different functions in a loop

Anytime that you are tempted to use assign and a loop, you should consider using lapply (or sapply) and a list instead.

Consider this alternative:
[1] 4
[1] 12
[1] 3
[,1] [,2] [,3]
 [1,]    2    3    4
 [2,]    3    4    5
 [3,]    4    5    6
 [4,]    5    6    7
 [5,]    6    7    8
 [6,]    7    8    9
 [7,]    8    9   10
 [8,]    9   10   11
 [9,]   10   11   12
[10,]   11   12   13

Hope this helps,