[R] Using ADF.Test

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Wed Jun 10 13:29:57 CEST 2009


Achim Zeileis wrote:

[...]

>  is.vector(as.vector(...)) is not necessarily TRUE. Consider
>
>   x <- cars[, 1, drop=FALSE]
>   is.vector(x)
>   is.vector(as.vector(x))
>   identical(x, as.vector(x))


interesting.  i wonder why as.vector does not give, at the very least, a
warning when the result of its application is not a vector.  the purpose
of as.vector, one might guess, is to obtain a vector from whatever input
-- or have the statement fail if such a conversion is impossible. 

the 'help' page for as.vector does not really explain what as.vector
returns.  the section 'value' talks about vector, exclusively:

"Value:

     For 'vector', a vector of the given length and mode.  Logical
     vector elements are initialized to 'FALSE', numeric vector
     elements to '0', character vector elements to '""', raw vector
     elements to 'nul' bytes and list elements to 'NULL'.

     All attributes are removed from the answer if it is of an atomic
     mode."

fine, but what about as.vector?  the section 'description' says:

"'as.vector', a generic, attempts to coerce its argument into a
     vector of mode 'mode' (the default is to coerce to whichever mode
     is most convenient)."

fine, but what if the attempt is unsuccessful?  the following fails:

    as.vector(as.vector)
    # Error in as.vector(x, mode) :
    #  cannot coerce type 'closure' to vector of type 'any'

but as.vector(data.frame()) 'works', even though the result is not a
vector of type 'any' either.

perhaps the 'help' page might be made more helpful?

vQ




More information about the R-help mailing list