Difference between revisions of "Loop.R"
From Organic Design wiki
(comment) |
(Naming the loop) |
||
Line 5: | Line 5: | ||
# e.g. 1,2,3,4 2,3,4,5 3,4,5,6 etc | # e.g. 1,2,3,4 2,3,4,5 3,4,5,6 etc | ||
# ============================================================================== | # ============================================================================== | ||
− | |||
start <- 1 | start <- 1 | ||
loop <- 6 | loop <- 6 | ||
comp <- 4 | comp <- 4 | ||
− | + | loopId <- 0:(loop+comp-1) %% loop +1 | |
+ | |||
+ | loopName <- c(0,14,25, 35,60,87,132,146) | ||
for(i in seq(loop)){ | for(i in seq(loop)){ | ||
− | print(loops[seq(from=i, length=comp)]) | + | print(loopName[loops[seq(from=i, length=comp)]]) |
} | } | ||
+ | |||
+ | # Returns; | ||
+ | # 0 14 25 35 | ||
+ | # 14 25 35 60 | ||
+ | # 25 35 60 87 | ||
+ | # 35 60 87 0 | ||
+ | # 60 87 0 14 | ||
+ | # 87 0 14 25 |
Revision as of 22:43, 12 December 2005
- ==============================================================================
- Loop evaluation e.g. 6 parts, 4 comparisons
- this function is construting an array e.g. 1,2,3,4,5,6,1,2,3
- and then subsetting sequential arrays of length four from it
- e.g. 1,2,3,4 2,3,4,5 3,4,5,6 etc
- ==============================================================================
start <- 1 loop <- 6 comp <- 4 loopId <- 0:(loop+comp-1) %% loop +1
loopName <- c(0,14,25, 35,60,87,132,146)
for(i in seq(loop)){
print(loopName[loops[seq(from=i, length=comp)]])
}
- Returns;
- 0 14 25 35
- 14 25 35 60
- 25 35 60 87
- 35 60 87 0
- 60 87 0 14
- 87 0 14 25