Learn R Programming

itertools2 (version 0.1.1)

iseq: Iterators for sequence generation

Description

Constructs iterators that generate regular sequences that follow the seq family.

Usage

iseq(from = 1, to = 1, by = (to - from)/(length_out - 1), length_out = NULL, along_with = NULL)
iseq_len(length_out = NULL)
iseq_along(along_with = NULL)

Arguments

from
the starting value of the sequence
to
the end value of the sequence
by
increment of the sequence.
length_out
desired length of the sequence. A non-negative number, which for seq will be rounded up if fractional.
along_with
the length of the sequence will match the length of this argument

Value

sequence's iterator

Details

The iseq function generates a sequence of values beginning with from and ending with to. The sequence of values between are determined by the by, length_out, and along_with arguments. The by argument determines the step size of the sequence, whereas length_out and along_with determine the length of the sequence. If by is not given, then it is determined by either length_out or along_with. By default, neither are given, in which case by is set to 1 or -1, depending on whether to > from.

seq_along and seq_len return an iterator, which generates a sequence of integers, beginning with 1 and proceeding to an ending value

Examples

Run this code
it <- iseq(from=2, to=5)
unlist(as.list(it)) == 2:5

it2 <- iseq_len(4)
unlist(as.list(it2)) == 1:4

it3 <- iseq_along(iris)
unlist(as.list(it3)) == 1:length(iris)

Run the code above in your browser using DataLab