

ifelse {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)

