0
0
R Programmingprogramming~20 mins

Coordinate systems in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Coordinate Systems Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of coordinate transformation using base R
What is the output of this R code that converts Cartesian coordinates (x, y) to polar coordinates (r, theta)?
R Programming
cartesian_to_polar <- function(x, y) {
  r <- sqrt(x^2 + y^2)
  theta <- atan2(y, x)
  return(c(r = r, theta = theta))
}

result <- cartesian_to_polar(3, 4)
print(round(result, 2))
Ar 7.00, theta 0.93
Br 5.00, theta 0.93
Cr 5.00, theta 0.64
Dr 7.00, theta 0.64
Attempts:
2 left
💡 Hint
Recall that r is the distance from origin and theta is the angle in radians from the x-axis.
🧠 Conceptual
intermediate
1:30remaining
Understanding coordinate system origin shifts
If you shift the origin of a 2D Cartesian coordinate system by vector (2, -3), what are the new coordinates of point (5, 7)?
A(3, 10)
B(7, 4)
C(3, 4)
D(7, 10)
Attempts:
2 left
💡 Hint
Subtract the shift vector from the original point coordinates.
🔧 Debug
advanced
2:00remaining
Identify the error in coordinate rotation code
What error does this R code produce when rotating a point (x, y) by angle theta (in radians)?
R Programming
rotate_point <- function(x, y, theta) {
  x_new <- x * cos(theta) - y * sin(theta)
  y_new <- x * sin(theta) + y * cos(theta)
  return(c(x_new, y_new))
}

rotate_point(1, 0, pi / 2)
AReturns numeric vector c(1, 0) without rotation
BError: object 'theta' not found
CReturns numeric vector c(0, 1) as expected
DError: non-numeric argument to binary operator
Attempts:
2 left
💡 Hint
Check if all variables are defined and used correctly.
📝 Syntax
advanced
1:30remaining
Syntax error in coordinate transformation function
Which option contains the correct syntax for defining a function that converts polar to Cartesian coordinates in R?
A
polar_to_cartesian &lt;- function(r, theta) {
  x &lt;- r * cos(theta)
  y &lt;- r * sin(theta)
  return(c(x = x, y = y))
}
B
polar_to_cartesian &lt;- function(r, theta) {
  x &lt;- r * cos(theta)
  y &lt;- r * sin(theta)
  c(x = x, y = y)
}
C
polar_to_cartesian &lt;- function(r, theta) {
  x &lt;- r * cos(theta)
  y &lt;- r * sin(theta)
  return(x, y)
}
D
polar_to_cartesian &lt;- function(r, theta) {
  x = r * cos(theta)
  y = r * sin(theta)
  return(c(x, y))
}
Attempts:
2 left
💡 Hint
Check the return statement syntax and how multiple values are returned.
🚀 Application
expert
3:00remaining
Calculate distance between two points in different coordinate systems
Given point A in Cartesian coordinates (3, 4) and point B in polar coordinates (r = 5, theta = pi/3), what is the Euclidean distance between A and B?
A3.0
B4.0
C5.0
D0.6
Attempts:
2 left
💡 Hint
Convert point B to Cartesian coordinates first, then use distance formula.