Chapter 20 Attributes

20.2 Access functions for common attributes

Dedicated access functions may be prepared for frequently used attributes such as element names.

// Element name, the following two sentences are synonymous
x.attr("names");
x.names();

The code example below shows how to access common attributes.

Vector v
v.attr("names"); // Element names
v.names();       // Element names

Matrix m;
m.ncol();  // Number of columns
m.nrow();  // Number of rows
m.attr(“dim”) = NumericVector::create( nrows, ncols );
m.attr(“dimnames”) = List::create( row_names, col_names );

DataFrame df;
df.attr(“names”);     // column names
df.attr(“row.names”); // row names

List L;
L.names(); // Element names