Full_Name: Murray Smith
Version: 2.2.1
OS: Windows XP
Submission from: (NULL) (202.36.29.1)


order() will not allow a complex vector for its first argument. This contrasts
with sort() which will happily sort a complex vector.

While this may not be regarded as a bug by some, it is annoying for anyone who
makes frequent use of complex numbers.

The problem occured in the Windows version 2.2.1 of R, but it has been present
in earlier versions.
> version
         _              
platform i386-pc-mingw32
arch     i386           
os       mingw32        
system   i386, mingw32  
status                  
major    2              
minor    2.1            
year     2005           
month    12             
day      20             
svn rev  36812          
language R       

An example demonstrating the problem:
x <- rep(2:1, c(2, 2)) + 1i*c(4, 1, 2, 3)
> x
[1] 2+4i 2+1i 1+2i 1+3i
> order(x)
Error in order(x) : unimplemented type 'complex' in 'orderVector1'

However sort() works with complex arguments
> sort(x)
[1] 1+2i 1+3i 2+1i 2+4i

The problem can be worked around either by 
> order(Re(x), Im(x))
[1] 3 4 2 1

or, because order() allows subsequent arguments to be complex, by using a
constant vector for the first argument 
> order(numeric(length(x)), x)
[1] 3 4 2 1

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to