subset                 package:base                 R Documentation

_S_u_b_s_e_t_t_i_n_g _V_e_c_t_o_r_s _a_n_d _D_a_t_a _F_r_a_m_e_s

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

     Return subsets of vectors or data frames which meet conditions.

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

     subset(x, ...)

     ## Default S3 method:
     subset(x, subset, ...)

     ## S3 method for class 'data.frame':
     subset(x, subset, select, drop = FALSE, ...)

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

       x: object to be subsetted.

  subset: logical expression.

  select: expression, indicating columns to select from a data frame.

    drop: passed on to '[' indexing operator.

     ...: further arguments to be passed to or from other methods.

_D_e_t_a_i_l_s:

     For ordinary vectors, the result is simply 'x[subset &
     !is.na(subset)]'.

     For data frames, the 'subset' argument works similarly on the
     rows.  Note that 'subset' will be evaluated in the data frame, so
     columns can be referred to (by name) as variables.

     The 'select' argument exists only for the method for data frames.
     It works by first replacing names in the selection expression with
     the corresponding column numbers in the data frame and then using
     the resulting integer vector to index the columns.  This allows
     the use of the standard indexing conventions so that for example
     ranges of columns can be specified easily.

     The 'drop' argument is passed on to the indexing method for data
     frames.

_V_a_l_u_e:

     An object similar to 'x' contain just the selected elements (for a
     vector), rows and columns (for a data frame), and so on.

_A_u_t_h_o_r(_s):

     Peter Dalgaard

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

     '[',  'transform'

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

     subset(airquality, Temp > 80, select = c(Ozone, Temp))
     subset(airquality, Day == 1, select = -Temp)
     subset(airquality, select = Ozone:Wind)

     with(airquality, subset(Ozone, Temp > 80))

