Skip to main content Link Search Menu Expand Document (external link)

Procedure 7: Selecting and Filtering from a Character Vector

Once a Vector has been named, attaching a label to each value, it can be selected using the [] square bracket structure. In this example, the age for Tom needs to be extracted by typing:

Ages["Tom"]

img.png

Run the line of script to console:

img_1.png

Tom’s age is returned as 22, rather the value in the Vector carrying the label “Tom” is returned as 22.

To select more than one label, it is a matter of creating a Vector with the criteria then passing that Vector inside the [] square brackets. In this example, selecting Tom and Dick:

Ages[c("Tom","Dick")]

img_2.png

Run the line of script to console:

img_3.png


Jube™. © Jube Holdings Limited 2022 to present.