Course Content
R Introduction: Part I
1. Basic Syntax and Operations
R Introduction: Part I
Namings
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:
Subject | Grade |
Math | 80 |
Physics | 75 |
English | 95 |
Literature | 100 |
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:
Item | Price |
Sofa | 340 |
Armchair | 150 |
Dining table | 115 |
Dining chair | 45 |
Bookshelf | 160 |
You need to save the prices within the prices
vector and name each price with the respective item.
- Create a vector of prices and assign it to the
prices
variable. - Assign items' names (they are saved in the
items
variable) toprices
vector' items. - Output the
prices
vector.
Everything was clear?