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:

BucketList$VectorExample
a-list-and-the-dollar-in-r-to-return.png

Run the line of script to console:

a-vector-contained-in-a-list-written-to-the-r-console.png

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:

BucketList$VectorExample["Tom"]
showing-how-sub-set-can-work-on-a-list-as-if-it-were-a-vector-in-r.png

Run the line of script to console:

a-variable-returned-from-a-vector-from-a-list-in-r.png

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