xpssSortCases: Sorts data ascending or descending order

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/xpssSortCases.R

Description

R implementation of the SPSS SORT CASES argument. xpssSortCases reorders the sequence of cases in the dataset based on the values of one or more variables.

Usage

1
xpssSortCases(x, variables = NULL, order ="A")

Arguments

x

a (non-empty) data.frame or input data of class "xpssFrame".

variables

atomic character or character vector with the names of the variables. Also rownames can be used to sort the data.

order

atomic character or character vector containing either "A" for ascending order or "D" for descending order.

Details

The argument order has to be of the same length as the argument variables. Optionally, the sorting can be specified in ascending or descending order for any variable. It is also possible to use combinations of ascending and descending order for different variables.

Value

Returns a sorted xpssFrame.

Author(s)

Andreas Wygrabek

See Also

sort order

Examples

1
2
3
data(fromXPSS)

xpssSortCases(fromXPSS, variables = c("V4", "V7_1", "V7_2"), order = c("A","D","A"))

Example output

              V1           V2 V3 V4      V5 V5_kl2     V6 V6_kl3 V7_1  V7_2
1           Audi           A8  1  1   1.380      1 62.000      3  310 113.0
2            BMW         328i  1  1   9.231      1 33.400      3  193 107.3
3       Cadillac           NA  2  1   6.536      1     NA     NA  275    NA
4      Chevrolet       Malibu  2  1 135.126      2 16.535      1  170 107.0
5       Chrysler         300M  2  1  30.696      2 29.184      2  253 113.0
6       Chrysler SebringCoupe  2  1   7.854      1 19.840      1  163 103.7
8          Dodge           NA  2  2  16.767      1     NA     NA  175    NA
7          Dodge    RamPickup  2  2 227.061      2 19.460      1  230 138.6
9           Ford     F-Series  2  2  80.620      2 26.934      2  220 138.5
10         Honda       Accord  3  1 230.902      2 15.350      1  135 106.9
11         Lexus        ES300  3  1  24.072      1 31.504      3  210 105.1
12         Lexus        RX300  3  2  51.238      2 34.604      3  220 103.0
14 Mercedes-Benz        CL500  1  1   0.954      1 85.500      3  302 113.6
13 Mercedes-Benz       SLK230  1  1   1.526      1 41.000      3  185  94.5
15        Nissan       Altima  3  1  88.094      2 20.390      2  155 103.1
16        Nissan           NA  3  2  42.574      2     NA     NA  170    NA
17        Nissan       Xterra  3  2  54.158      2 22.798      2  170 104.3
18    Oldsmobile           NA  2  2  24.361      1     NA     NA  185    NA
19        Toyota       Celica  3  1  33.269      2 16.875      1  140 102.4
20        Toyota  LandCruiser  3  2   9.835      1 51.728      3  230 112.2

translateSPSS2R documentation built on May 30, 2017, 4:31 a.m.