Tsallaka zuwa abun ciki
Justice Tech School

Vector Arithmetic

Operations work on whole vectors element by element. Shorter vectors are recycled.

Example
a <- c(1, 2, 3)
b <- c(10, 20, 30)
print(a + b)
print(a * 2)
print(a > 1)
print(sum(a), mean(b))
print(1:3 + c(10, 20, 30))

Exercise

Whole vector math.

a  b

Quiz Test

What happens with different lengths?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.