
Vector Definition in R
This tutorial will guide you through the process of defining vectors in R, complete with a hands-on example.
First, open the R console.
Begin by assigning a name to your vector, followed by the assignment operator.
v <- c(1,2,3)
Enter the elements of your vector, enclosed in parentheses.
Remember, each element must be comma-separated.
After creating your vector, it's ready for various vector calculations.
Example:
Let's start by creating two vectors:
v <- c(1,2,3)
w <- c(4,1,2)
Now, perform a vector addition:
> v+w
[1] (5,3,5)
The output is a new vector y, composed of these elements.