Complex Type
In this page:
Complex Type
R natively supports complex numbers with the complex type, written as a+bi using i for the imaginary unit, like 3+4i. Standard arithmetic operators work directly on complex numbers. This is less commonly used than the other basic types but is fully built in for scientific and engineering computation.
Note: Mod() computes a complex number's magnitude, and Re()/Im() extract its real and imaginary parts.
Example: Complex Type
z <- 3 + 4i
cat(class(z), "\n")
cat("Magnitude:", Mod(z), "\n")
cat("Real part:", Re(z), "Imaginary part:", Im(z), "\n")
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: