sort-methods | R Documentation |

The methods below return a sorted version of the data frame or data set, given as first argument.

```
## S3 method for class 'data.frame'
sort(x,decreasing=FALSE,by=NULL,na.last=NA,...)
## S3 method for class 'data.set'
sort(x,decreasing=FALSE,by=NULL,na.last=NA,...)
```

`x` |
a data frame or data set. |

`decreasing` |
a logical value, should sorting be in increasing or decreasing order? |

`by` |
a character name of variable names, by which to sort; a formula giving the variables, by which to sort; NULL, in which case, the data frame / data set is sorted by all of its variables. |

`na.last` |
for controlling the treatment of 'NA's. If 'TRUE', missing values in the data are put last; if 'FALSE', they are put first; if 'NA', they are removed |

`...` |
other arguments, currently ignored. |

A sorted copy of `x`

.

```
DF <- data.frame(
a = sample(1:2,size=20,replace=TRUE),
b = sample(1:4,size=20,replace=TRUE))
sort(DF)
sort(DF,by=~a+b)
sort(DF,by=~b+a)
sort(DF,by=c("b","a"))
sort(DF,by=c("a","b"))
```

memisc documentation built on March 31, 2023, 7:29 p.m.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.