interleave               package:gdata               R Documentation

_I_n_t_e_r_l_e_a_v_e _R_o_w_s _o_f _D_a_t_a _F_r_a_m_e_s _o_r _M_a_t_r_i_c_e_s

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

     Interleave rows of data frames or Matrices.

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

     interleave(..., append.source=TRUE, sep=": ", drop=FALSE)

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

     ...: objects to be interleaved 

append.source: Boolean Flag.  When 'TRUE' (the default) the argument
          name will be appended to the row names to show the source of
          each row. 

     sep: Separator between the original row name and the object name.

    drop: logical - If the number of columns in output matrix is 1,
          whether matrix should be returned or a vector 

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

     This function creates a new matrix or data frame from its
     arguments.

     The new object will have all of the rows from the source objects
     interleaved. IE, it will contain row 1 of object 1, followed by
     row 1 of object 2, .. row 1 of object 'n', row 2 of object 1, row
     2 of object 2, ... row 2 of object 'n' ...

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

     Matrix containing the interleaved rows of the function arguments.

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

     Gregory R. Warnes gregory.r.warnes@pfizer.com

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

     'cbind', 'rbind', 'combine'

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

     # Simple example
     a <- matrix(1:10,ncol=2,byrow=TRUE)
     b <- matrix(letters[1:10],ncol=2,byrow=TRUE)
     c <- matrix(LETTERS[1:10],ncol=2,byrow=TRUE)
     interleave(a,b,c)

     # Useful example:
     #
     # Create a 2-way table of means, standard errors, and # obs

     g1 <- sample(letters[1:5], 1000, replace=TRUE)
     g2 <- sample(LETTERS[1:3], 1000, replace=TRUE )
     dat <- rnorm(1000)

     stderr <- function(x) sqrt( var(x,na.rm=TRUE) / nobs(x) )

     means   <- aggregate.table( dat, g1, g2, mean )
     stderrs <- aggregate.table( dat, g1, g2, stderr )
     ns      <- aggregate.table( dat, g1, g2, nobs )
     blanks <- matrix( " ", nrow=5, ncol=3)

     tab <- interleave( "Mean"=round(means,2),
                        "Std Err"=round(stderrs,2),
                        "N"=ns, " " = blanks, sep=" " )

     print(tab, quote=FALSE)

     # Using drop to control coercion to a lower dimensions:

     m1 <- matrix(1:4)
     m2 <- matrix(5:8)

     interleave(m1, m2, drop=TRUE)  # This will be coerced to a vector

     interleave(m1, m2, drop=FALSE) # This will remain a matrix

