[R] Unclear documentation on 'numeric' and 'integer' (R-lang.pdf)

Peng Yu pengyu.ut at gmail.com
Wed Jan 20 23:37:56 CET 2010


R-lang.pdf has the following description in Section 3.1.1.

"""
Any number typed directly at the prompt is a constant and is evaluated.
> 1
[1] 1
Perhaps unexpectedly, the number returned from the expression 1 is a
numeric. In most
cases, the difference between an integer and a numeric value will be
unimportant as R will
do the right thing when using the numbers.
"""

I'm not sure if I understand it. According to the following example
adding 'L' after '1', doesn't change the mode from 'numeric' to
'integer'. Could somebody clarify this and revise the document to make
this point clearer?

> interogate<-function(f) {
+   print(f(1))
+   x=1
+   print(f(x))
+   x=1L
+   print(f(x))
+   print(f(1L))
+   print(f(as.integer(1)))
+ }
>
> interogate(typeof)
[1] "double"
[1] "double"
[1] "integer"
[1] "integer"
[1] "integer"
> interogate(mode)
[1] "numeric"
[1] "numeric"
[1] "numeric"
[1] "numeric"
[1] "numeric"
> interogate(storage.mode)
[1] "double"
[1] "double"
[1] "integer"
[1] "integer"
[1] "integer"
>



More information about the R-help mailing list