0

Data:

d2

# A tibble: 5 x 2
  Dist      n
  <chr> <int>
1 003     194
2 011     180
3 013     157
4 017     279
5 026     208

From the above data "d2" I want to order the values in descending order for column 'n'. Also want top 2 values.

When I am using

arrange(desc(d2$n))

It is showing error:

Error in UseMethod("arrange_") : 
  no applicable method for 'arrange_' applied to an object of class "c('integer', 'numeric')"

Can anyone help me?

zx8754
  • 52,746
  • 12
  • 114
  • 209
Sanky Ach
  • 333
  • 8
  • 23

1 Answers1

3

since you did not provide your data, here is a solution for some random data:

d2 <- tibble(m = runif(5)*10, n = rnorm(5)) 

d2 %>%
  arrange(desc(n)) %>%
  slice(1:3)

Alternatively you can use the top_n function:

d2 %>% top_n(3, n)

The difference between these two methods is that top_n does not sort the result.

Cettt
  • 11,460
  • 7
  • 35
  • 58