Sort data frame by variable(s)    package:epicalc    R Documentation

_S_o_r_t _d_a_t_a _f_r_a_m_e _b_y _v_a_r_i_a_b_l_e(_s)

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

     Sort the whole dataset by one or more variables

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

     sortBy(..., dataFrame = .data)

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

     ...: index variable(s) used for sorting

dataFrame: Destination data frame where all variables of the same
          length are sorted

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

     The whole dataset, and the variables outside, can be sorted by an
     index variable(s) inside the (...).

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

     Virasakdi Chongsuvivatwong <cvirasak@medicine.psu.ac.th>

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

     'sort', 'order'

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

     sbp <- c(120, 100, 110, 120, 140, 120,  NA,  NA) 
     dbp <- c( 80,  80,  70,  80,  70,  NA,  70,  60)
     .data <- data.frame(sbp, dbp)
     use(.data)
     age <- c(37, 32, 24, 33, 31, 30, 26, 25)
     age2 <- age^2
     sortBy(age)
     pack()
     des()
     .data
     sortBy(age, decreasing=TRUE)
     .data

     ## Note that the argument of 'sortBy' must not be concatenated vectors
     data(Familydata)
     use(Familydata)
     .data
     sortBy(money, sex) # correct
     .data
     use(Familydata) # Read in the dataset afresh
     sortBy(c(money, sex)) # errors.
     .data

