complex
and
as.complex
functions create vectors of complex numbers.
complex(length=0, data=NULL, real=0, imaginary=0, modulus=1, argument=0) is.complex(x) as.complex(x)
complex(data=x)
is the same as
as.complex(x)
, and
complex(length=n, data=x)
is the same as
rep(as.complex(x), length=n)
.
complex
returns a simple object (i.e., a vector) of mode
"complex"
.
If
real
and/or
imaginary
are specified, the real and
imaginary parts of the result are set from them, using the defaults
if necessary.
If
modulus
and/or
argument
are specified, the modulus and
argument of the result are set from them, using the defaults
if necessary.
If either of
real
or
imaginary
is specified, neither
modulus
nor
argument
may be specified, and vice versa.
is.complex
returns
TRUE
if
x
is of mode
"complex"
, and
FALSE
otherwise.
Its behavior is unaffected by any attributes of
x
; for example,
x
could
be a complex array.
as.complex
returns
x
if
x
is a simple object of mode
"complex"
, and
otherwise a complex object of the same length as
x
and with data resulting
from coercing the elements of
x
to mode
"complex"
.
Attributes are deleted.
The "
+
" within the rectangular representation of a complex number has the
usual precedence.
Both the
as.complex
and
is.complex
functions are generic;
currently there are no methods written for them.
unit.disk <- complex(arg=runif(50, -pi, pi)) #50 random complex numbers, uniform on the unit circle sqrt(as.complex(-5:5)) # shift the phase of a vector zz.shift <- complex(modulus=Mod(zz), argument=Arg(zz)+pi)