Vector arithmetic (element-wise)
📖 Scenario: You are working with two sets of numbers representing daily temperatures in two different cities. You want to compare them by adding, subtracting, multiplying, and dividing the temperatures element by element.
🎯 Goal: Build a simple R program that creates two numeric vectors, sets a length variable, performs element-wise arithmetic operations on the vectors, and prints the results.
📋 What You'll Learn
Create two numeric vectors named
city1_temps and city2_temps with exact valuesCreate a variable
n that stores the length of the vectorsUse element-wise arithmetic operations: addition, subtraction, multiplication, and division
Print the results of each arithmetic operation
💡 Why This Matters
🌍 Real World
Element-wise vector arithmetic is useful when comparing or combining data points from two related datasets, like temperatures from two cities over several days.
💼 Career
Data analysts and scientists often use vector operations to quickly process and analyze numerical data without writing loops.
Progress0 / 4 steps