Description Usage Arguments Details Value Examples
serpentine
sorts data in a serpentine fashion (alternating between ascending and
descending orders) for all variables specified. mixed_serpentine
sorts the data with
ascending or descending sorts for every variable specified except the last, which is serpentine
sorted.
1 2 3 | serpentine(data = NULL, ..., random_num = 1)
mixed_serpentine(data = NULL, ...)
|
data |
is the data.frame to be sorted |
... |
are the variables to serpentine sort, in the given order. In
|
random_num |
is a random number to break ties randomly. This is most helpful when all variables on which the data is sorted are categorical as it is more liekly there are several rows of data with identical values on each category. Default is 1 so that results are reproducable. |
This is helpful in complex sampling designs with implicit stratification, as it reduces the variation in the stratified outcome for adjacent sampled units and thus reduces the overall sampling error. Serpentine sorts are commonly used in NCES surveys.
A data.frame with equal size as the original data, but sorted differently.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # All variables except first are serpentine sorted
serpentine(data = mtcars, cyl, mpg)
serpentine(data = mtcars, cyl, vs, mpg)
# Same sort variables, but different resulting order because changing random number
serpentine(data = mtcars, vs, am)
serpentine(data = mtcars, vs, am, random_num = 5)
# Changing the random number has minimal effect when a non-cateogrical variable is included
serpentine(data = mtcars, cyl, vs, mpg)
serpentine(data = mtcars, cyl, vs, mpg, random_num = 23)
# cyl, and vs are ascending sorted while mpg is serpentine sorted
mixed_serpentine(mtcars, cyl, vs, mpg)
# cyl is ascending, vs is descending, and mpg is serpentine sorted
mixed_serpentine(mtcars, cyl, dplyr::desc(vs), mpg)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.