i

R Programming Complete Tutorial

R Arithmetic Vector Operations

We will start with basic arithmetic operations. Vector follows all the basic rules of arithmetic operations like addition, subtraction, multiplication, and division. Suppose in case of v1+v1, it will add element-wise.  The first element of v1, 3 will be added to the first element of v2, 14, and the result will be 17. It will continue the same for all the elements of the vector.

Vector element recycling is a bit tricky. The length of v1 is 6, whereas its 2 for v3. Usually, it's not possible to add these vectors, but due to this, recycling property length of v3 will be changed to 6 by taking the same pair thrice. Now, v3 will be treated as c (2, 5, 2, 5, 2, 5). Then it will do the regular addition.

 Finally, we can sort the vector elements just using the sort () function.