[R] Difference between 10 and 10L

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri May 4 08:05:16 CEST 2012


On 04/05/2012 00:43, William Dunlap wrote:
>    >  class(10)
>    [1] "numeric"
>    >  class(10L)
>    [1] "integer"
>    >  class(10i)
>    [1] "complex"
>
> Why not 10I for integer?  Perhaps because "I" and "l"
> look too similar, perhaps because "i" and "I" sound
> too similar.  The "L" does not mean "long": integers
> are 4 bytes long.

Actually it does: this notation dates from the C language on 16-bit 
computers where integers were 16-bits and longs were 32-bit (and R has 
no 'long' type).

The author of this in R never explained why he chose the notation, but 
it is shorter than as.integer(10), and more efficient as the coercion is 
done at parse time.

(C has a different convention: 10 is integer, 10. is double.  Changing 
to that would have altered existing code, since e.g. 4294967296 is not a 
valid integer.)

>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
>> Of brwin338
>> Sent: Thursday, May 03, 2012 4:33 PM
>> To: r-help at r-project.org
>> Subject: [R] Difference between 10 and 10L
>>
>>
>> Good Evening
>> We have been searching through the R documentation manuals without success on this
>> one.
>> What is the purpose or result of the "L" in the following?
>>
>> n=10
>> and
>> n=10L
>>
>> or
>> c(5,10)
>> versus
>> c(5L,10L)
>>
>> Thanks
>> Joe
>>
>>
>>
>> Thanks
>> Joe
>>
>>
>> 	[[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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.
>
> ______________________________________________
> R-help at 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.


-- 
Brian D. Ripley,                  ripley at 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



More information about the R-help mailing list