search for: makenestedloops

Displaying 1 result from an estimated 1 matches for "makenestedloops".

2009 Dec 19
4
expand.grid game
...=0, i2=9, i2++) { [... other nested loops ] test = test + (i1 + i2 + [...] == 17); } [...] } but here the number of for loops, N, should remain a variable. In despair I coded this in R as a wicked eval(parse()) construct, and it does produce the expected result after an awfully long time. makeNestedLoops <- function(N=3){ startLoop <- function(ii, start=1, end=9){ paste("for (i", ii, " in seq(",start,", ",end,")) {\n", sep="") } first <- startLoop(1) inner.start <- lapply(seq(2, N), startLoop, start=0) calculation <- p...