Chapter 8 Vector

8.3 Member functions

Member functions (also called as Methods) are functions that is attached to an individual object. You can call member functions f() of object v in the form of v.f().

The Vector object in Rcpp have member functions listed below.

8.3.1 length(), size()

Returns the number of elements of this vector object.

8.3.2 names()

Returns the element names of this vector object as CharacterVector.

8.3.3 offset( name ), findName( name )

Returns numerical index of the element specified by character string name.

8.3.4 offset( i )

Returns numerical index of the element specified by numerical index i after doing bounds checking to ensure i is valid.

8.3.5 fill( x )

Fills all the element of this vector object with scalar value x.

8.3.6 sort()

Returns a vector that sorts this vector object in ascending order.

8.3.7 assign( first_it, last_it )

Assigns values specified by the iterator first_it and last_it to this vector object.

8.3.8 push_back( x )

Append a scalar value x to the end of this vector object.

8.3.9 push_back( x, name )

Append a scalar value x to the end of this vector object and set name of the element as character string name.

8.3.10 push_front( x )

Append a scalar value x to the front of this vector object.

8.3.11 push_front( x, name )

Append a scalar value x to the front of this vector and set name of the element as character string name.

8.3.12 begin()

Returns an iterator pointing to the first element of this vector. See the Chapter 28 Iterator.

8.3.13 end()

Returns an iterator pointing to the end of the vector (one past the last element of this vector). See the Chapter 28 Iterator.

8.3.14 cbegin()

Returns a const iterator pointing to the first element of the vector. See the Chapter 28 Iterator.

8.3.15 cend()

Returns a const iterator pointing to the end of the vector (one past the last element of this vector). See the Chapter 28 Iterator.

8.3.16 insert( i, x )

Insert scalar value x to the position pointed by numerical index i. And returns the iterator pointing the inserted element.

8.3.17 insert( it, x )

Insert scalar value x to the position pointed by iterator it. And returns the iterator pointing the inserted element.

8.3.18 erase(i)

Erase element at the position pointed by numerical index i. And returns the iterator pointing the element just behind the erased element.

8.3.19 erase(it)

Erase element at the position pointed by iterator it. And returns the iterator pointing the element just behind the erased element.

8.3.20 erase( first_i, last_i )

Erase elements from the position pointed by numerical index first_i to last_i - 1. And returns the iterator pointing the element just behind the erased elements.

8.3.21 erase( first_it, last_it )

Erase elements from the position pointed by iterator first_it to last_it - 1. Return the iterator pointing the element just behind the erased elements.

8.3.22 containsElementNamed(name)

Returns true if this vector contains an element with the name specified by character string name.

8.4 Static member functions

Static member function is functions that is attached to the class from which an object being molded. You can call static member functions in the form such as NumericVector::create().

8.4.1 get_na()

Returns the NA value of this Vector class. See chapter 24 for NA.

8.4.2 is_na(x)

Returns true if a vector element specified by x is NA.

8.4.3 create( x1, x2, ...)

Creates a Vector object containing elements specified by scalar value x1 and x2. Maximum number of arguments are 20.

8.4.4 import( first_it , last_it )

Creates a Vector object filled with the range of data specified by iterator from first_it to last_it - 1.

8.4.5 import_transform( first_it, last_it, func)

Creates a Vector object filled with the range of data specified by iterator from first_it to last_it - 1 that is transformed by function specified by func.