Just for fun:

roundDown <- function(x, digits = 2)
{
currplaces <- nchar(as.character((floor(x))))

x <- x * 10 ^ (digits - currplaces)
x <- floor(x)
x <- x / (10 ^ (digits - currplaces))

x

}

> roundDown(1.98, 2)
[1] 1.9
> roundDown(1.98, 1)
[1] 1
> roundDown(1.98, 3)
[1] 1.98
>
>
> roundDown(298, 2)
[1] 290
> roundDown(298, 1)
[1] 200
>
> roundDown(298, 3)
[1] 298


Sarah

On Fri, Sep 16, 2011 at 12:31 PM, Dimitri Liakhovitski
<dimitri.liakhovit...@gmail.com> wrote:
> In other words, I am looking for something like floor, but more
> flexible - as it should allow me to:
> turn 1.98 into 1.9 or
> turn 298 into 290,
> etc.
> Dimitri
>
> On Fri, Sep 16, 2011 at 12:28 PM, Dimitri Liakhovitski
> <dimitri.liakhovit...@gmail.com> wrote:
>> Hello!
>>
>> What function would allow me to "round" down, rather than up?
>> For example, x<-1.98
>> I'd like to get 1.9 - rather than 2.0.
>>
>> Reason - I am creating a minimum for an axis for a plot, and I need it
>> to be lower than x (which, in turn, is the lowest number already).
>> Thank you!
>>
>> --

-- 
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to