0

CSV file is here: IMDB movies dataset. It contains 180 lines as sample.

How using row_number I will be able to find the lowest row?

I'm able to find longest. How to find shortest?

#longest movie
(longest <- imdb_movies.csv %>%
    filter(row_number(desc(Runtime_in_min)) == 1))
Supek
  • 47
  • 1
  • 7
  • 2
    You could use the `which.max` and `which.min` functions. – Dave2e Aug 30 '19 at 20:52
  • 1
    What if you remove the `desc` option? – TJ87 Aug 30 '19 at 20:52
  • 2
    Are you trying to find the row number of the shortest movie, or just the shortest movie? A more natural `dplyr` way would be something like `data %>% arrange(Runtime_in_min) %>% slice(1)`. – Gregor Thomas Aug 30 '19 at 20:58
  • Or `imdb_movies %>% filter(Runtime_in_min == min(Runtime_in_min))`. This also allows for the possibility that there is more than one movie with the same shortest runtime. – Mako212 Aug 30 '19 at 21:02
  • `top_n(imdb_movies.csv, -1, Runtime_in_min)` – camille Aug 30 '19 at 21:25

1 Answers1

0
movies <- imdb_movies.csv
movies[movies$Runtime_in_min == max(movies$Runtime_in_min),] # Longest
movies[movies$Runtime_in_min == min(movies$Runtime_in_min),] # Shortest
Monk
  • 407
  • 3
  • 8