Search notes:

R function: order

#
# Compare with -> rank
#

v <- c ( 41, 18, 37, 26)
order(v)
# [1] 2 4 3 1

# Definition of order:
#  v[order(v)] is in increasing order:

v[order(v)]
# [1] 18 26 37 41

df <- data.frame(foo=c(  2,  3,  1),
                 bar=c( 22, 11, 22),
                 baz=c(111,333,222))


order(df$bar)
# [1] 2 1 3


df[order(df$bar)        , ] # NOTE! the empty parameter «, ]»
#   foo bar baz
# 2   3  11 333
# 1   2  22 111
# 3   1  22 222

order(df$bar, df$foo)
# [1] 2 3 1

df[order(df$bar, df$foo), ]
#   foo bar baz
# 2   3  11 333
# 3   1  22 222
# 1   2  22 111

df[order(df$bar, df$baz), ]
#   foo bar baz
# 2   3  11 333
# 1   2  22 111
# 3   1  22 222

df[order(df$bar, df$baz)  ]
#   bar foo baz
# 1  22   2 111
# 2  11   3 333
# 3  22   1 222

Github repository about-r, path: /functions/order.R

See also

Index to (some) R functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758201478, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/functions/order(88): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78