ifelse                 package:base                 R Documentation

_C_o_n_d_i_t_i_o_n_a_l _E_l_e_m_e_n_t _S_e_l_e_c_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     'ifelse' returns a value with the same shape as 'test' which is
     filled with elements selected from either 'yes' or 'no' depending
     on whether the element of 'test' is 'TRUE' or 'FALSE'. If 'yes' or
     'no' are too short, their elements are recycled.

_U_s_a_g_e:

     ifelse(test, yes, no)

_A_r_g_u_m_e_n_t_s:

    test: a logical vector

     yes: return values for true elements of 'test'.

      no: return values for false elements of 'test'.

_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.

_S_e_e _A_l_s_o:

     'if'.

_E_x_a_m_p_l_e_s:

     x <- c(6:-4)
     sqrt(x)#- gives warning
     sqrt(ifelse(x >= 0, x, NA))# no warning

     ## Note: the following also gives the warning !
     ifelse(x >= 0, sqrt(x), NA)

