From Martin Maechler <maechler@stat.math.ethz.ch>  Mon Jan 26 17:58:54 1998
From: Martin Maechler <maechler@stat.math.ethz.ch> (Martin Maechler)
Date: Mon, 26 Jan 1998 18:58:54 +0100
Subject: Factor variables are not vectors...
In-Reply-To: <Pine.SUN.3.95.980126083031.935A-100000@chekov> (message from
 Thomas Lumley on Mon, 26 Jan 1998 08:34:35 -0800 (PST))
Message-ID: <199801261758.SAA08574@sophie.ethz.ch>

	[diverted from R-help to R-devel;  this gets technical ...]
>>>>> "TL" == Thomas Lumley <thomas@biostat.washington.edu> writes:

    TL> On Mon, 26 Jan 1998, Jim Lindsey wrote:

    >> 2. Factor variables are not vectors!!
    >> is.vector(gl(20,2,40)) gives FALSE

    TL> Even stranger 

    R> is.vector(factor(1:3))# [1] FALSE
    R> is.factor(factor(1:3))# [1] TRUE
    R> is.vector(as.vector(factor(1:3)))# [1] TRUE
    R> is.factor(as.vector(factor(1:3)))# [1] TRUE

    TL> so that factor variables *can* be vectors, but aren't naturally.

and why should they, really?

	(BTW, they are not either in S-plus, by the way).

In your code, shouldn't you test rather 

	if(!is.array(..))

instead?


-------------------

But if we are bashing on  is.vector(.):

Here is an excerpt from a mail I wrote more than 9 months ago:

##- Date: Mon, 7 Apr 97 09:33:51 +0200
##- From: Martin Maechler <maechler@stat.math.ethz.ch>
##- Cc: r-devel@stat.math.ethz.ch
##- In-Reply-To: <199704062058.IAA09618@stat1.stat.auckland.ac.nz> (message from
##- 
##- Ross>> Another reasonable definition of "vector" is !is.array(x).
##- Ross>> or possibly "isVector(x) == 1 && !is.array(x)

##- Yes, I think
##- 		isVector(x) == 1 && !is.array(x)
##- 
##- is the way to go, at least for   mode = 'any'
##- 
##- Now, for the 2nd argument  mode = '...' :
##- I think it should always be more restrictive, i.e.,
##- 	  is.vector(OB, mode= MODE)   <-->   is.vector(OB) &&  MODE.test(OB)
##- 
##- which is not the case currently [[correcting a typo in $RHOME/TASKS l.449-451]

 is.vector(call("ls"))			#[1] FALSE --- but SHOULD be 'TRUE'
 is.vector(call("ls"), mode='language')	#[1] TRUE
 is.vector(call("ls"), mode='call')	#[1] FALSE

## [[here, is.vector(call("ls"), mode='any')  should really return TRUE]]


-----
Martin Maechler
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Factor variables are not vectors...
Martin Maechler