log10scaleround = function(x) {
v = log10(c(1, 2, 5, 10))
lx = log10(x)
10^(floor(lx) + vapply(lx %% 1, function(r) v[which.min(abs(v - r))], 0))
}
log10scaleround(c(0.2589254, 20.5671765))
[1] 0.2 20.0
The above function can round numbers in log10 scale to numbers like .1, .2, .5, 1, 2, 5, 10, 20, 50, 100.
Given a boundary like 0.2, 20.0, I want to fill in numbers in between like .5, 1, 2, 5, 10.
That is, for input like 0.2589254, 20.5671765, I want the output be c(.2, .5, 1, 2, 5, 10, 20).
I could use a for-loop to solve this problem. But it is not efficient. How to program this efficiently in R?