[R] rounding to whole number

Sarah Goslee sarah.goslee at gmail.com
Thu Mar 20 20:52:48 CET 2014


What about:

> ceiling(data[,2:3])
  A B
1 0 1
2 3 1
3 3 3
4 2 3

Note that ceiling is referenced in ?round

Thanks for the clear reproducible example.

Sarah


On Thu, Mar 20, 2014 at 3:42 PM, Kristi Glover
<kristi.glover at hotmail.com> wrote:
> Hi R User,
> I was trying to convert a decimal value into integral (whole number). I used round function but some of the cells have the value less than 0.5 and it converted into 0. But I wanted these cell to have 1 instead of 0. Another way, I could multiply by 10. But l did not want it because it affected my results later.
> I was wondering about how I can convert 0.2 to 1. For example
> data<-structure(list(site1 = structure(1:4, .Label = c("s1", "s2",
> "s3", "s4"), class = "factor"), A = c(0, 2.3, 2.6, 1.3), B = c(0.5,
> 0.17, 2.9, 3)), .Names = c("site1", "A", "B"), class = "data.frame", row.names = c(NA,
> -4L))
> output<-structure(list(site1 = structure(1:4, .Label = c("s1", "s2",
> "s3", "s4"), class = "factor"), A = c(0L, 3L, 3L, 2L), B = c(1L,
> 1L, 3L, 3L)), .Names = c("site1", "A", "B"), class = "data.frame", row.names = c(NA,
> -4L))
>
> Thanks for your suggestions in advance.
> cheers,
> KG
>
-- 
Sarah Goslee
http://www.functionaldiversity.org




More information about the R-help mailing list