0
0
R Programmingprogramming~30 mins

Coordinate systems in R Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Coordinate Systems
📖 Scenario: You are working with a simple map of a city park. The park has several landmarks, and you want to store their positions using coordinates.
🎯 Goal: Create a list of landmarks with their x and y coordinates, set a reference point, calculate the distance of each landmark from the reference point, and print the distances.
📋 What You'll Learn
Create a list called landmarks with named vectors for each landmark's x and y coordinates
Create a variable called reference_point as a named vector with x and y coordinates
Calculate the Euclidean distance from each landmark to the reference_point using a for loop and store results in a vector called distances
Print the distances vector
💡 Why This Matters
🌍 Real World
Coordinate systems help us locate places on maps, in games, or in real life, like finding landmarks in a park.
💼 Career
Understanding coordinates and distance calculations is useful in fields like geography, game development, robotics, and data visualization.
Progress0 / 4 steps
1
Create landmarks with coordinates
Create a list called landmarks with these exact entries: Fountain = c(x = 3, y = 4), Bench = c(x = 7, y = 1), Playground = c(x = 2, y = 8)
R Programming
Need a hint?

Use list() to create a list and c(x = value, y = value) for coordinates.

2
Set the reference point coordinates
Create a variable called reference_point as a named vector with x = 0 and y = 0
R Programming
Need a hint?

Use c(x = 0, y = 0) to create the reference point vector.

3
Calculate distances from reference point
Create a numeric vector called distances and use a for loop with variable name to calculate the Euclidean distance from each landmark in landmarks to reference_point. Store each distance in distances with the same names as landmarks.
R Programming
Need a hint?

Use sqrt(dx^2 + dy^2) to calculate distance and assign it to distances[name].

4
Print the distances
Write a print() statement to display the distances vector
R Programming
Need a hint?

Use print(distances) to show the distances.