complex package:base R Documentation _C_o_m_p_l_e_x _V_e_c_t_o_r_s _D_e_s_c_r_i_p_t_i_o_n: Basic functions which support complex arithmetic in R. _U_s_a_g_e: complex(length.out = 0, real = numeric(), imaginary = numeric(), modulus = 1, argument = 0) as.complex(x, ...) is.complex(x) Re(z) Im(z) Mod(z) Arg(z) Conj(z) _A_r_g_u_m_e_n_t_s: length.out: numeric. Desired length of the output vector, inputs being recycled as needed. real: numeric vector. imaginary: numeric vector. modulus: numeric vector. argument: numeric vector. x: an object, probably of mode 'complex'. z: an object of mode 'complex', or one of a class for which a methods has been defined. ...: further arguments passed to or from other methods. _D_e_t_a_i_l_s: Complex vectors can be created with 'complex'. The vector can be specified either by giving its length, its real and imaginary parts, or modulus and argument. (Giving just the length generates a vector of complex zeroes.) 'as.complex' attempts to coerce its argument to be of complex type: like 'as.vector' it strips attributes including names. All forms of 'NA' and 'NaN' are coerced to a complex 'NA', for which both the real and imaginary parts are 'NA'. Note that 'is.complex' and 'is.numeric' are never both 'TRUE'. The functions 'Re', 'Im', 'Mod', 'Arg' and 'Conj' have their usual interpretation as returning the real part, imaginary part, modulus, argument and complex conjugate for complex values. Modulus and argument are also called the _polar coordinates_. If z = x + i y with real x and y, for r = Mod(z) = sqrt{x^2 + y^2}, and phi = Arg(z), x = r*cos(phi) and y = r*sin(phi). They are all generic functions: methods can be defined for them individually or via the 'Complex' group generic. In addition, the elementary trigonometric, logarithmic and exponential functions are available for complex values. 'as.complex' and 'is.complex' are primitive, so positional matching is used and any names of supplied arguments are ignored. This may not be true of methods for 'as.complex'. _S_4 _m_e_t_h_o_d_s: 'as.complex' is primitive and can have S4 methods set. 'Re', 'Im', 'Mod', 'Arg' and 'Conj' constitute the S4 group generic 'Complex' and so S4 methods can be set for them individually or via the group generic. _R_e_f_e_r_e_n_c_e_s: Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S Language_. Wadsworth & Brooks/Cole. _E_x_a_m_p_l_e_s: require(graphics) 0i ^ (-3:3) matrix(1i^ (-6:5), nrow=4) #- all columns are the same 0 ^ 1i # a complex NaN ## create a complex normal vector z <- complex(real = stats::rnorm(100), imaginary = stats::rnorm(100)) ## or also (less efficiently): z2 <- 1:2 + 1i*(8:9) ## The Arg(.) is an angle: zz <- (rep(1:4,len=9) + 1i*(9:1))/10 zz.shift <- complex(modulus = Mod(zz), argument= Arg(zz) + pi) plot(zz, xlim=c(-1,1), ylim=c(-1,1), col="red", asp = 1, main = expression(paste("Rotation by "," ", pi == 180^o))) abline(h=0,v=0, col="blue", lty=3) points(zz.shift, col="orange")