NamingsNamings

Now you know how to create vectors. Assume that the vector represents valuable information, for example, grades (on a scale from 1 to 100). But grades themselves most likely will not be understood by another person.

Assume that the grades are the next:

SubjectGrade
Math80
Physics75
English95
Literature100

You know how to create a vector with grades. But how do you assign specific names to values? You can do it by assigning to names(vector) the vector of names. The vector in parenthesis is the vector of which elements you want to name. Let's look at the example.

That looks much better.

Task

Assume you run a local store with furniture. The items and prices are shown below:

ItemPrice
Sofa340
Armchair150
Dining table115
Dining chair45
Bookshelf160

You need to save the prices within the prices vector and name each price with the respective item.

  1. Create a vector of prices and assign it to the prices variable.
  2. Assign items' names (they are saved in the items variable) to prices vector' items.
  3. Output the prices vector.

Everything was clear?

Section 2. Chapter 7
toggle bottom row