In a right-angled triangle, the tangent of an angle is:

The length of the side opposite the angle is divided by the length of the adjacent side.

The abbreviation is tan is the following.

**tan(θ) = opposite / adjacent**

**tan in R**

The tan() is a built-in R function that calculates the tangent value of numeric value. It accepts a numeric value as a parameter and returns the tangent value. The **tanpi()** method calculates the tangent of the input value, the multiples of **π.**

To calculate the tangent in R programming, use the tan() function.

**Syntax**

`tan(x)`

**Parameters**

The tan() function takes a numeric value.

**Example**

```
x1 <- -45
x2 <- -60
tan(x1)
tan(x2)
```

**Output**

```
[1] -1.619775
[1] -0.3200404
```

**Applying pi to the tan() function**

The **pi **is an inbuilt constant whose value is **3.141593. **Let’s pass the pi to the tan() function and see the output.

```
x1 <- pi
x2 <- pi / 3
tan(x1)
tan(x2)
```

**Output**

```
[1] -1.224647e-16
[1] 1.732051
```

**Applying a tan() function to Vector**

To create a Vector in R, use the c() function. First, let’s create a vector and pass that vector to the tanpi() function.

```
dt <- c(1, 0.5, -1, -0.25, 0.5, 2 / 3)
tanpi(dt)
```

**Output**

```
[1] 0.000000 NaN 0.000000 -1.000000 NaN -1.732051
Warning message:
In tanpi(dt) : NaNs produced
```

That is it for tan() function in R.

**See also**

Krunal Lathiya is an Information Technology Engineer by education and web developer by profession. He has worked with many back-end platforms, including Node.js, PHP, and Python. In addition, Krunal has excellent knowledge of Data Science and Machine Learning, and he is an expert in R Language. Krunal has written many programming blogs, which showcases his vast expertise in this field.