So in essence, it always provides the same output, but saves space and speed.

Thanks everyone!
 - Alex

On 05/15/2014 01:06 PM, Prof Brian Ripley wrote:
On 15/05/2014 11:54, Alexander Engelhardt wrote:
Hello R-help,

I keep noticing R functions that don't compare integers like
   if(x == 2)
but instead
   if(x == 2L)

Is this a long integer? Also, when do the two notations have a different
effect on the code?

2L is an integer. both in the mathematical sense and the sense of
typeof().  2 is a double with a value that is a mathematical integer.
They are stored differently, and in x == 2 'x' will be coerced to
double, often unnecessarily.  Which is why careful authors write e.g.

length(x) == 2L

as length() the vast majority of the time gives an integer (especially
where length-2 is expected).

Thanks in advance,
  Alex



______________________________________________
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