This question already has answers here:
Rounding numbers to nearest 10 in R
(2 answers)
Closed 1 year ago.
How can I round the following numbers:
16554.2644 and 2238.987
to:
16550 and 2240
and
16560 and 2230
Thanks
Divide the number by 10, round using either floor or ceil and then multiply by 10.
Related
This question already has answers here:
How can I tell R to round correctly?
(2 answers)
Round up from .5
(7 answers)
Closed 6 months ago.
I want to round the number 6.85 to 1 digit after decimal expected answer is 6.9
This question already has answers here:
Round up from .5
(7 answers)
Closed 3 years ago.
The help of round states that ‘go to the even digit’ is used for rounding.
How can I have a consistent rounding mechanism?
For example:
This rounds up.
round(1.5, 0)
2
This rounds down.
round(4.5, 0)
4
In both cases I want it to round up.
But I also want 1,4 to round down and 1,7 to round up.
There is the functions floor() and ceiling()
floor(1.5)
1
ceiling(1.5)
2
This question already has answers here:
Difference between Math.Floor() and Math.Truncate()
(13 answers)
Closed 5 years ago.
What is the difference between Math.Floor() and Math.Truncate() in .NET?
For example, Math.Floor(4.4) = 4 Math.Truncate(4.4) = 4.
These function behave differently for negative numbers.
Math.Truncate(-4.5) = -4
Math.Floor(-4.5) = -5
Math.Floor rounds down Math.Ceiling rounds up and Math.Truncate rounds towards zero. Thus, Math.Truncate is like Math.Floor for positive numbers, and like Math.Ceiling for negative numbers.
This question already has answers here:
Digit sum function in R
(4 answers)
Closed 7 years ago.
I've got this simple question: how can I change a vector consisting of 10 numbers into a vector consisting of ten numbers which are the sum of the figures of the first numbers? So 11 in the first vector becomes 2, 234 becomes 9.
We can use str_extract_all from stringr to get the individual numbers, convert them to numeric and get the sum.
library(stringr)
sapply(str_extract_all(c(11, 234), '\\d'), function(x) sum(as.numeric(x)))
This question already has answers here:
Controlling number of decimal digits in print output in R
(4 answers)
Closed 9 years ago.
I am trying to have sum of two values in R with 6 decimal places but it only returns with 5.
85.85+0.01302778
# [1] 85.86303
I tried
round(85.85+0.01302778,6)
but it does not work.
Actually sum(85.85,0.01302778) gives only 5 decimals and I did not find any scope of decimal places in ?sum.
Any suggestions
Try this to get 6 digits:
> options(digits=8)
> 85.85+0.01302778
[1] 85.863028