| mfor | R Documentation |
mfor is a multivariate version of for.
mfor(...)
... |
arguments to |
If exactly one variable is specified, the behaviour is similar to
for. See section Examples.
break breaks out of an mfor loop,
next halts the processing of the current
iteration and advances the looping index; exactly the same as a
for, while, or
repeat loop.
The seqs in an mfor loop is evaluated at the start of the loop;
changing it subsequently does affect the loop. If any sequence in seqs
has length zero, the body of the loop is skipped. Otherwise, the variables
vars are assigned in turn the elements of the sequences of
seqs. You can assign to any of vars within the body of the
loop, but this will not affect the next iteration. When the loop terminates,
vars remains as the variables containing their last values.
Unlike for, the sequences will not be coerced to
a vector or to a pairlist. Instead, their subsetting
([[), length, and
lengths methods will be used.
mfor returns NULL invisibly. It also sets vars to the
last used values of seqs, or to NULL if any sequence was length
zero.
for for the single variate for loop.
# when exactly one variable is specified,
# the behaviour is similar to 'for'
mfor(i, 1:5, print(1:i))
# 'mfor' works on classed objects, 'for' does not
mfor(date, Sys.time() + 0:9, print(date))
# sequences are recycled as necessary,
# with a warning for fractional recycling
mfor(i, j, k, list(1:4, 6:10, 11:15), {
print(c(i = i, j = j, k = k))
})
# mfor works well with data frames
mfor( col , cex, main ,
data.frame(palette.colors(3), 1:3, paste("title", 1:3)),
graphics::plot(x = 1:5, col = col, cex = cex, main = main,
pch = 16)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.