Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
What are vectors?
Vector operations
9. Arithmetic with vectors
Indexing and filtering


Correct! We can also perform calculations with two vectors of the same length. Just as before, the operations will be memberwise. The result is a third vector. Here is an example:

salaries + bonuses

Here is how R will calculate the result:

  salaries 3400 2800 5600 4200 3100 3800 ... 
+ bonuses   400  800  600  200  100  800 ... 
=          3800 3600 6200 4400 3200 4600 ...


We'd like to see how the employee salaries for this year changed from the ones for last year. No one was fired/hired in the course of this year.

The employee salaries from a year ago are stored in a vector named salaries_last_year. This year's salaries are stored in the vector salaries. Create the vector called salaries_difference representing salary differences between this year and the last year.