In R, we have several ways to sort data. The easiest way is to use the sort() function (see the code for the simplest one-dimensional data):
> set.seed(123) > x<-rnorm(100) > head(x) [1] -0.56047565 -0.23017749 1.55870831 0.07050839 0.12928774 1.71506499 > y<-sort(x) > head(y) [1] -2.309169 -1.966617 -1.686693 -1.548753 -1.265396 -1.265061
Let's look at another way to sort data. The dataset used is called nyseListing, which is included in the R package called fImport, shown here:
library(fImport) data(nyseListing) dim(nyseListing) head(nyseListing)
The output is shown here:
In total, we have 3,387 observations, each with 4 variables. The dataset is sorted by Symbol, as in the tickers of individual stocks. Assume that we want to sort them by Name, as shown here:
> x<-nyseListing[order(nyseListing$Name),] > head(x...