I have the following data:
> vec
[1] 0.0 0.5 1.0 1.4 1.9 2.4 3.1 3.6 4.1 4.6 5.0 5.5 6.0 6.5 7.0 7.4 7.9 8.4 9.1
which I need to round to the nearest .5.
Let me be more specific: 1.4 becomes 1.5, and 1.9 becomes 2.0. Also, 2.4 becomes 2.5, and 3.1 becomes 3.0. And so on. The vector I expect is:
> vec
[1] 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0
Any ideas?
Many thanks.
Don't know what language you're using, but the math would be NUM = INTEGER (NUM x 2) / 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With