[R] Is k equivalent to k:k ?

Marcus Davy MDavy at hortresearch.co.nz
Wed Dec 8 23:38:29 CET 2004


Bringing up an old topic on a small technicality.

In the help documentation on seq.

Value:

     The result is of 'mode' '"integer"' if 'from' is (numerically
     equal to an) integer and 'by' is not specified.

The arguement in seq specifying length also creates "double" which is not obvious in the wording, as "by" is not specified but
the object is double.

> typeof(seq(from=1, length=1))
[1] "double"



marcus



>>> Martin Maechler <maechler at stat.math.ethz.ch> 3/08/2004 3:15:45 AM >>>
>>>>> "Georgi" == Georgi Boshnakov <georgi.boshnakov at umist.ac.uk>
>>>>>     on Mon, 2 Aug 2004 15:46:37 +0100 writes:

    Georgi> Hi, I wonder if the following (apparent)
    Georgi> inconsistency is a bug or feature.  

a feature "of course".

    Georgi> Since scalars are simply vectors of length one I
    Georgi> would think that a and a:a produce the same result. 

Why would you?  
Have you read the documentation for ":" carefully?  

{Part this topic, namely that a numeric constant such as "4"
 is a "double" in R (but integer in S-plus since S+5.0)
 should probably finally end up in the R FAQ ...
}

Regards, Martin Maechler

    Georgi> For example,

    >> identical(4.01,4.01:4.01)
    Georgi> [1] TRUE

    Georgi> However,

    Georgi> identical(4,4:4)
    Georgi> [1] FALSE

    Georgi> and

    >> identical(4.0,4.0:4.0)
    Georgi> [1] FALSE

    Georgi> A closer look reveals that the colon operator produces objects of different class, e.g.

a closer look wouldn't have been necessary had you read and
understood the documentation.


    >> class(4)
    Georgi> [1] "numeric"
    >> class(4.0)
    Georgi> [1] "numeric"

    Georgi> but

    >> class(4:4)
    Georgi> [1] "integer"
    >> class(4.0:4.0)
    Georgi> [1] "integer"


    Georgi> Georgi Boshnakov
    Georgi> ------------------------------------------------------------------------------
    Georgi> Dr Georgi Boshnakov                                tel.: +44  (0)161 200 3684
    Georgi> Mathematics Department                           email: georgi.boshnakov at umist.ac.uk 
    Georgi> UMIST
    Georgi> P O Box 88    
    Georgi> Manchester M60 1QD
    Georgi> UK


    Georgi> [[alternative HTML version deleted]]

	    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	    do read the posting guide why you should reconfigure
	    your e-mail software

______________________________________________
R-help at stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help 
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html 

______________________________________________________

The contents of this e-mail are privileged and/or confidenti...{{dropped}}




More information about the R-help mailing list