Here are modified floor and ceiling functions that solve your problem:

my.floor <-function(x,my.base){
floor(x/my.base)*my.base
}

my.ceiling <-function(x,my.base){
ceiling(x/my.base)*my.base
}

Base = 0.5
my.floor(126.6,Base)   #[1] 126.5
my.ceiling(126.6,Base) #[1] 127

Base = 1
my.floor(126.6,Base) #[1] 126
my.ceiling(126.6,Base) #[1] 127

HTH

Pierre


On Wed, Aug 25, 2010 at 4:38 PM, Gandhi, Puneet - RSCH AMRS <
p.gandhi@baml.com> wrote:

> Hi All,
>
> Is there any function in R which does what Floor or Ceiling in Excel.
>
> Excel can take 2 arguments to FLOOR function while R doesn't.
>
> I need the following which is done in excel
>
> Base = 0.5
> Floor(126.6,Base) = 126.5
> Ceiling(126.6, Base) = 127
>
>
> Base = 1
> Floor(126.6, Base) = 126
> Ceiling(126.6, Base) = 127
>
> I tried round, floor, ceiling, trunc in R but none does this job.
>
> Pls Help/Thanks
> Puneet
>
> ----------------------------------------------------------------------
> This message w/attachments (message) is intended solely ...{{dropped:7}}
>
> _______________________________________________
> R-SIG-Finance@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions
> should go.
>

	[[alternative HTML version deleted]]

