PigWolf - 1 year ago 94

R Question

I have a bearing of X degrees and I wish to calculate other bearings either side of X. We all know a circle has 360 degrees but if I'm given a bearing of 0 degrees and I wish to calculate the bearings + and - 30 degrees of 0 how can I program this such that I am looking for 0 - 30 = 330 degs and 0 + 30 = 30 degrees?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

The modulus operator (`%%`

) can help you with that

```
x <- 0
(x+30) %% 360
# [1] 30
(x-30) %% 360
# [1] 330
```

In this case it will keep all values in the range `[0, 360)`

. See the `?"%%"`

help page for more information or even the wikipedia page for these types of operations

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**