smartbind 1.68 KB
smartbind               package:gtools               R Documentation

_E_f_f_i_c_i_e_n_t _r_b_i_n_d _o_f _d_a_t_a _f_r_a_m_e_s_y, _e_v_e_n _i_f _t_h_e _c_o_l_u_m_n _n_a_m_e_s _d_o_n'_t _m_a_t_c_h

_D_e_s_c_r_i_p_t_i_o_n:

     Efficient rbind of data frames, even if the column names don't
     match

_U_s_a_g_e:

     smartbind(...)

_A_r_g_u_m_e_n_t_s:

     ...: Data frames to combine

_V_a_l_u_e:

     The returned data frame will contain: 

 columns: all columns present in any provided data frame

    rows: a set of rows from each provided data frame, with values in
          columns not present in the given data frame filled with
          missing ('NA') values.

     The data type of columns will be preserved, as long as all data
     frames with a given column name agree on the data type of that
     column.  If the data frames disagree, the column will be converted
     into a character strings.  The user will need to coerce such
     character columns into an appropriate type.

_A_u_t_h_o_r(_s):

     Gregory R. Warnes warnes@bst.rochester.edu

_S_e_e _A_l_s_o:

     'rbind', 'cbind'

_E_x_a_m_p_l_e_s:

       df1 <- data.frame(A=1:10, B=LETTERS[1:10], C=rnorm(10) )
       df2 <- data.frame(A=11:20, D=rnorm(10), E=letters[1:10] )

       # rbind would fail
     ## Not run: 
       rbind(df1, df2)
       # Error in match.names(clabs, names(xi)) : names do not match previous
       # names:
       #     D, E
     ## End(Not run)
       # but smartbind combines them, appropriately creating NA entries
       smartbind(df1, df2)