Created
July 22, 2014 06:10
-
-
Save chainsawriot/ae1fbf91734a72a83f57 to your computer and use it in GitHub Desktop.
A reply to Ron Yick https://twitter.com/RonaldYick/status/491014320902651904
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iris[c(3,2,1),] # index the dataframe by an "indices vector", will only pick the first three rows in reversed order | |
order(iris$Sepal.Length) # generate an "indices vector" based on the ranked value of Sepal Length | |
# therefore | |
iris[order(iris$Sepal.Length, decreasing=TRUE),] | |
# is ordered by row based on the value of Sepal Length, you still need to specify the column required. | |
# try these also | |
iris[order(iris$Sepal.Length, decreasing=TRUE),1] # just the first col, by index | |
iris[order(iris$Sepal.Length, decreasing=TRUE),c(1,3)] # 1st and 3rd, by index vector | |
iris[order(iris$Sepal.Length, decreasing=TRUE),c("Sepal.Length", "Petal.Length")] # by column name vector | |
iris[order(iris$Species, iris$Sepal.Length, decreasing=TRUE),c("Sepal.Length", "Species")] # order first by Species then by Sepal. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment