YouTip LogoYouTip

R Func Sin

# Convert angles to radians angle_rad <- angle_deg *pi/180 # Calculate sine values print("sin values:") print(round(sin(angle_rad), 4)) # Calculate cosine values print("cos values:") print(round(cos(angle_rad), 4)) # Calculate tangent values (note: 90 degrees is infinite) print("tan values (note: 90 degrees is infinite):") print(round(tan(angle_rad), 4))

Executing the above code produces:

 "sin values:" 0.0000 0.5000 0.7071 0.8660 1.0000 "cos values:" 1.0000 0.8660 0.7071 0.5000 0.0000 "tan values (note: 90 degrees is infinite):" 0.0000 0.5774 1.0000 1.7321 Inf

Using the arctangent function atan2(), you can calculate the polar angle of a point (x, y) on a plane:

Example

# Calculate the polar angle of point (1,1) (should be 45 degrees)

 angle_rad <-atan2(1, 1)

 angle_deg <- angle_rad *180/pi

print(paste("Angle of point (1,1):", angle_deg, "degrees"))

# Calculate the polar angle of point (-1, 1) (should be 135 degrees)

 angle_rad <-atan2(1, -1)

 angle_deg <- angle_rad *180/pi

print(paste("Angle of point (-1,1):", angle_deg, "degrees"))

Executing the above code produces:

 "Angle of point (1,1): 45 degrees" "Angle of point (-1,1): 135 degrees"

Image 4: R Language Examples R Language Examples

← R Func SprintfR Func Seq β†’