Say I have a vector of integers: tt <- c(26000L, 26000L, 25333L, 25333L, 25343L, 24667L, 24667L, 24667L,
23667L)
I want to replace these integers within the interval of 500 and get:
26000 26000 25500 25500 25500 25000 25000 25000 24000
Say I have a vector of integers: tt <- c(26000L, 26000L, 25333L, 25333L, 25343L, 24667L, 24667L, 24667L,
23667L)
I want to replace these integers within the interval of 500 and get:
26000 26000 25500 25500 25500 25000 25000 25000 24000
You can use round_any
from the plyr
library.
library(plyr)
round_any(as.numeric(tt), 500)
[1] 26000 26000 25500 25500 25500 24500 24500 24500 23500
round_any(as.numeric(tt), 500, f = floor)
[1] 26000 26000 25000 25000 25000 24500 24500 24500 23500
round_any(as.numeric(tt), 500, f = ceiling)
[1] 26000 26000 25500 25500 25500 25000 25000 25000 24000
I'm not sure about your rounding logic, but what about
round(as.numeric(tt) / 500) * 500
# [1] 26000 26000 25500 25500 25500 24500 24500 24500 23500