Vectors are one-dimension arrays that can hold numeric data, character data, or logical data, but not a mixture of different Data Types.
Problem:
Create a Vector Variable in R
Solution:
In R, we can construct a vector from some given values using the operator c(…)
1. Create 2 vectors with numeric values using c() function.
2. Create a Vector with elements of Character Data Type like below:
3. Create a Vector with elements of Boolean Data Type
4. Check the Sum of two numeric Vectors
If we sum two vectors in R, it takes the element-wise sum. Let’s check the values in Vector V1 and V2 that we defined earlier and then create a new Vector as V5 to sum up the elements
So the v5 vector elements are 5(1+4), 7(2+5) and 9 (3+6) which is the sum of the individual elements of vector v1 and v2.
Let’s take a look at the code:
Now, to learn more about vectors in R, please follow the below links:
Happy learning and happy practicing!