Amanda1988 <[EMAIL PROTECTED]> wrote:

> 
> I was having a problem with a little simple function I wrote in R and I think
> the problem was that R is representing fractional numbers in binary floating
> point and not decimal notation, so sometimes I was having extra data points
> counted. Is there a way to cast a number stored in a variable as an integer?

To store a decimal fraction as the nearest integer, I would
start with

as.integer(round(x))

where x is the decimal fraction.

Almost no computer language stores fraction numbers in decimal.
If your code expects such storage, you might consider a
different way of coding the problem. If you were to show your R
code, someone might suggest a better way of doing thigs.

In particular, for regular fractional sequences, it is better
practice to generate them as integers, than divide by the common
divisor, than to use seq() with fractions. In other cases, it
can be helpful to use the length.out= argument to seq(), rather
than the to= argument.

HTH

-- 
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

______________________________________________
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