In dplyr
, there is arrange
to do the ordering
library(dplyr)
DF <- DF %>%
arrange(confirmed)
-output
DF
# country confirmed
#2 Slovakia 1269
#1 Germany 10910
#3 US 175663
If we don't want to use DF <-
use the %<>%
from magrittr
library(magrittr)
DF %<>%
arrange(confirmed)
Or in case, we wanted to use order
, an option is to pull
the column 'confirmed, do the order
and slice
the data based on that order
DF %>%
pull(confirmed) %>%
order %>%
slice(DF, .)
# country confirmed
#2 Slovakia 1269
#1 Germany 10910
#3 US 175663
Or another way is
DF %>%
pull(confirmed) %>%
order %>%
`[`(DF, .,)
# country confirmed
#2 Slovakia 1269
#1 Germany 10910
#3 US 175663
data
DF <- structure(list(country = c("Germany", "Slovakia", "US"),
confirmed = c(10910L,
1269L, 175663L)), class = "data.frame", row.names = c("1", "2",
"3"))