Data objects include vectors, matrices, lists and dataframes.

Vectors

Vectors are ordered sequences of the same type; you can create them with the operator , which combines its arguments. Below we create a vector of five integers and access its third element. In R, the first element of a vector has index 1 (not 0, as in Python and C):

Matrices

Matrices are two-dimensional containers of items all having the same class. The following example also shows the use of the function (attributes comprise customizable metadata about data objects; can be used to list, get and set attribute values).

Lists

Lists are ordered collections that allow mixtures of different classes. They can be addressed by index, but are often most useful if you create them with name-value pairs so that you can access elements by name using the construction .

Using lists with many keys as a map (sometimes called a hash, or a dictionary) can have significant performance implications. You can reduce such issues by using ):

Dataframes

Dataframes are to matrices what lists are to vectors. They are two-dimensional tables where the values within a column need to be the same type, but values between columns do not. Data read from an external file will be put into a dataframe. Following is an example of a dataframe.

Arrays

Arrays are multidimensional vectors, whose attributes include for dimensionality and which may also contain names for each dimension under ; a matrix is simply a two-dimensional array, where . An array created with dimension 2, 3, 4 creates four 2 x 3 matrices:

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Access Statement
CVW material development is supported by NSF OAC awards 1854828, 2321040, 2323116 (UT Austin) and 2005506 (Indiana University)