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
--
Brian D. Ripley, rip...@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
______________________________________________
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.