17) Sub setting and referencing objects with a name

This Blog entry is from the Data Structures section in Learn R.

The most useful and common way to navigate a list is by referencing the entry in the list  by name then sub setting the object thereafter.  The approach of referencing list objects by name,  then sub setting thereafter can serve to make a distinction between a list and a vector in day to day use.

The list created beforehand has several objects with the names TempsExample, GenderExample,MatrixExample and VectorExample.  Start by returning a vector object by name:


Run the line of script to console:


It can be seen that the object stored under the name "VectorExample" is a labeled Vector.  As this is a Vector,  it is possible to further subset this using techniques outlined in procedure 25.  For example,  to return Tom’s age from the Vector,  type:


Run the line of script to console:


It can be observed that the vector was drawn from the list by name, then subset as is customary for a vector.