We can tell R to add two sets of numbers together. It will then add the
first number from x
to the first number from y
, and so on. However, x
and
y
should be the same length. We can check their length using the length()
function
> x = c(1, 6, 2)
> y = c(1, 4, 3)
> length(x)
[1] 3
> length(y)
[1] 3
> x + y
[1] 2 10 5
x
and y
in the variables x.length
and y.length
respectively.+
operator.Use the code below as a starting point.