subset                package:arules                R Documentation

_S_u_b_s_e_t_t_i_n_g _I_t_e_m_s_e_t_s, _R_u_l_e_s _a_n_d _T_r_a_n_s_a_c_t_i_o_n_s

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

     Provides the generic function 'subset' and S4 methods to subset
     associations or transactions (itemMatrix) which meet certain
     conditions (e.g., contains certain items or satisfies a minimum
     lift).

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

     subset(x, ...)

     ## S4 method for signature 'itemMatrix':
     subset(x, subset, ...)

     ## S4 method for signature 'itemsets':
     subset(x, subset, ...)

     ## S4 method for signature 'rules':
     subset(x, subset, ...)

     ## S4 method for signature 'itemMatrix':
     subset(x, subset, ...)

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

       x: object to be subsetted.

  subset: logical expression indicating elements to keep.

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

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

     'subset' works on the rows/itemsets/rules of 'x'. The  expression
     given in 'subset' will be evaluated using 'x', so the items
     (lhs/rhs/items) and the columns in the quality data.frame can be
     directly referred to by their names.

     Important operators to select itemsets containing items specified
     by their  labels are '%in%' (select itemsets matching _any_ given
     item),  '%ain%' (select only itemsets matching _all_ given item)
     and  '%pin%' ('%in%' with partial matching).

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

     An object of the same class as 'x' containing only the elements
     which satisfy the conditions.

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

     'itemMatrix-class', 'itemsets-class', 'rules-class',
     'transactions-class'

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

     data("Adult")
     rules <- apriori(Adult)

     ## select all rules with item "marital-status=Never-married" in 
     ## the right-hand-side and lift > 2
     rules.sub <- subset(rules, subset = rhs %in% "marital-status=Never-married" 
         & lift > 2)

     ## use partial matching for all items corresponding to the variable
     ## "marital-status"
     rules.sub <- subset(rules, subset = rhs %pin% "marital-status=")

     ## select only rules with items "age=Young" and "workclass=Private" in
     ## the left-hand-side
     rules.sub <- subset(rules, subset = lhs %ain% 
         c("age=Young", "workclass=Private"))

