Re: [Rd] is.vector(as.vector(x)) is FALSE

2004-10-18 Thread Peter Dalgaard
Uwe Ligges <[EMAIL PROTECTED]> writes:

> ... I think I'd rather expect that
> 
>as.vector(x1mat, mode = "list")
> 
> also removes the dim attributes.

Just checked, Splus seems to satisfy is.vector(as.vector(x)) for list
matrices and data frames. The R docs have

 '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).  The attributes of 'x' are removed.

so I think there is a case for deeming the current behaviour to be a bug...

-- 
   O__   Peter Dalgaard Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics 2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark  Ph: (+45) 35327918
~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] is.vector(as.vector(x)) is FALSE

2004-10-18 Thread Uwe Ligges
Achim,
you are right, in principle, but I think I'd rather expect that
  as.vector(x1mat, mode = "list")
also removes the dim attributes.
Uwe

Achim Zeileis wrote:
On Sun, 17 Oct 2004 01:51:47 + (UTC) Gabor Grothendieck wrote:

The following, which was recently discussions on the rcom-l list,
is a situation where coercing x1mat to a vector using as.vector
results in an object that is.vector says is not a vector:
R> x1mat<-matrix(list(1,1.1,1+1i,"a",NA,NaN), 3, 2)
R> is.vector(as.vector(x1mat))
[1] FALSE

If you give it a particular mode, it produces a vector:
R> as.vector(x1mat, mode = "character")
[1] "1""1.1"  "1+1i" "a""NA"   "NaN" 
R> as.vector(x1mat, mode = "numeric")
[1] 1.0 1.1 1.0  NA  NA NaN
Warning messages: 
1: imaginary parts discarded in coercion 
2: out-of-range values treated as 0 in coercion to raw 

A somewhat similar and simpler example is:
R> x <- data.frame(a = 1:5, b = 6:10)
R> is.vector(as.vector(x))
[1] FALSE
because data.frames are also already vectors of mode "list". The man
page of as.vector provides a similar example with:
R> as.vector(x, mode = "numeric")
Error in as.vector(x, mode = "numeric") : (list) object cannot be
coerced to double
I had discussed this with Kurt (and maybe R-devel, but I cannot find it
in the archives) some time ago and the bottom line--if I recall
correctly--was that is.vector() and as.vector() do not behave in the
way that is.vector(as.vector(x)) always gives TRUE (or an error).
Z
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] is.vector(as.vector(x)) is FALSE

2004-10-18 Thread Achim Zeileis
On Sun, 17 Oct 2004 01:51:47 + (UTC) Gabor Grothendieck wrote:

> 
> The following, which was recently discussions on the rcom-l list,
> is a situation where coercing x1mat to a vector using as.vector
> results in an object that is.vector says is not a vector:
> 
>  R> x1mat<-matrix(list(1,1.1,1+1i,"a",NA,NaN), 3, 2)
>  R> is.vector(as.vector(x1mat))
>  [1] FALSE

If you give it a particular mode, it produces a vector:

R> as.vector(x1mat, mode = "character")
[1] "1""1.1"  "1+1i" "a""NA"   "NaN" 
R> as.vector(x1mat, mode = "numeric")
[1] 1.0 1.1 1.0  NA  NA NaN
Warning messages: 
1: imaginary parts discarded in coercion 
2: out-of-range values treated as 0 in coercion to raw 

A somewhat similar and simpler example is:

R> x <- data.frame(a = 1:5, b = 6:10)
R> is.vector(as.vector(x))
[1] FALSE

because data.frames are also already vectors of mode "list". The man
page of as.vector provides a similar example with:

R> as.vector(x, mode = "numeric")
Error in as.vector(x, mode = "numeric") : (list) object cannot be
coerced to double

I had discussed this with Kurt (and maybe R-devel, but I cannot find it
in the archives) some time ago and the bottom line--if I recall
correctly--was that is.vector() and as.vector() do not behave in the
way that is.vector(as.vector(x)) always gives TRUE (or an error).

Z

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] is.vector(as.vector(x)) is FALSE

2004-10-17 Thread Gabor Grothendieck

I would have thought it would be an error to attempt and fail.
Actually, to make it a vector all that has to be done is to zap the dim 
attribute:

   dim(x1mat) <- NULL  # now its a vector

It seems to know how to do that in the case of an atomic 
matrix, just not a non-atomic one.  Here it is for an
atomic matrix where it does return TRUE:

   is.vector(as.vector(matrix(1:12,4)))  # TRUE

  uni-bayreuth.de> writes:

: 
: maybe, the point is that is.vector "attempts to coerce its argument into a
: vector", but here it fails
: 
: is.matrix(as.vector(x1mat))
: [1] TRUE
: 
: Matthias
: 
: >
: > The following, which was recently discussions on the rcom-l list,
: > is a situation where coercing x1mat to a vector using as.vector
: > results in an object that is.vector says is not a vector:
: >
: >  R> x1mat<-matrix(list(1,1.1,1+1i,"a",NA,NaN), 3, 2)
: >  R> is.vector(as.vector(x1mat))
: >  [1] FALSE
: >
: > __
: > R-devel  stat.math.ethz.ch mailing list
: > https://stat.ethz.ch/mailman/listinfo/r-devel
: 
: __
: R-devel  stat.math.ethz.ch mailing list
: https://stat.ethz.ch/mailman/listinfo/r-devel
: 
:

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] is.vector(as.vector(x)) is FALSE

2004-10-17 Thread Matthias . Kohl
maybe, the point is that is.vector "attempts to coerce its argument into a
vector", but here it fails

is.matrix(as.vector(x1mat))
[1] TRUE

Matthias

>
> The following, which was recently discussions on the rcom-l list,
> is a situation where coercing x1mat to a vector using as.vector
> results in an object that is.vector says is not a vector:
>
>  R> x1mat<-matrix(list(1,1.1,1+1i,"a",NA,NaN), 3, 2)
>  R> is.vector(as.vector(x1mat))
>  [1] FALSE
>
> __
> [EMAIL PROTECTED] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[Rd] is.vector(as.vector(x)) is FALSE

2004-10-16 Thread Gabor Grothendieck

The following, which was recently discussions on the rcom-l list,
is a situation where coercing x1mat to a vector using as.vector
results in an object that is.vector says is not a vector:

 R> x1mat<-matrix(list(1,1.1,1+1i,"a",NA,NaN), 3, 2)
 R> is.vector(as.vector(x1mat))
 [1] FALSE

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel