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)

_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)

