iterator: Iterator

View source: R/iterator.R

IteratorR Documentation

Iterator

Description

A way to traverse a list, data.frame, matrix or vector.

Usage

iterator(x,method="ceil",type="vector",by=1)
## S3 method for class 'iterator'
print(x,...)
## S3 replacement method for class 'iterator'
Elem(x) <- value
Elem(x)
Elem(x) <- value
## S3 method for class 'iterator'
Elem(x)
## S3 method for class 'iterator'
x == y
## S3 method for class 'iterator'
x != y

Arguments

x

A variable with any type, or iterator object.

value

An value depending the method of the iterator.

y

An iterator.

method

Method of the iterator class. One of "ceil","col","row".

type

One of "vector","matrix","data.frame","list".

by

An integer value to iterate through element.

...

Anything the user want.

Details

iterator: is an object that helps a programmer to traverse the given object.

print.iterator: print an object of class iterator.

"Elem<-": access to element and change the value.

Elem: access to element.

Value

An object of class "iterator". This object holds 4 fields:

copy: deep copy of iterator. end: get iterator tha have access to points to the last element. equals: equality of iterators nextElem: move iterator to point to the next element using argument "by". prevElem: move iterator to point to the previous element using argument "by".

Author(s)

R implementation and documentation: Manos Papadakis <papadakm95@gmail.com>.

See Also

colShuffle, colVars, colmeans, read.directory

Examples


y<-rnorm(100)
x<-iterator(y,method="ceil",type="vector",by=1)

s<-0
while(x != x$end()){
	s <- s + Elem(x)
	x$nextElem()
}

all.equal(s,sum(y))

Rfast documentation built on Nov. 9, 2023, 5:06 p.m.