[R] as.complex

Patrick Burns pburns at pburns.seanet.com
Thu Oct 7 11:55:47 CEST 2004


Perhaps there could be an extra argument to as.complex that
controls whether parsing is standard or loose.

Patrick Burns

Burns Statistics
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

Prof Brian Ripley wrote:

>On Thu, 7 Oct 2004, Erich Neuwirth wrote:
>
>  
>
>>as.complex("2+1i") -> 2+1i
>>as.complex("2+i") -> NA
>>
>>Does somebody have a modified version of as.complex
>>which does the coercion in a less strict manner and
>>produces a complex number also for strings like the
>>second example?
>>
>>Perhaps it would even make sense to change the behavior
>>of as.complex to handle the second case.
>>After all, this is an established way of writing
>>complex numbers in some programming tools
>>able to deal with complex numbers.
>>    
>>
>
>R does document that 1i is required, and as.complex uses the same rules 
>for entering complex numbers as e.g. using them as part of an arithmetic 
>expression.  Consistency is very important in a programming language.
>
>It is easy to change 2+i to 2+1i using sub(), for example.
>
>  
>




More information about the R-help mailing list