If I wanted to round every value in a dataframe to the nearest set of values, for example c(0, 1)
. How would I go about doing this?
>toRound <- c(-2, 3, 4, 1, -1, 0, .5)
>magicFunction(toRound, c(0, 1))
c(0, 1, 1, 1, 0, 0, 1)
>magicFunction(toRound, c(-1, 1))
c(-1, 1, 1, 1, -1, round(runif(1,min=0,max=1), 0), 1)