Reputation: 84465
Apologies if I have missed where this has been asked before - I couldn't find it. I am learning about tibbles and the verb arrange
. I am wondering if there is a more efficient way to arrange
rows in descending order of total row NA count then I have done below? I am using the nycflights13
dataset.
library(nycflights13)
library(tidyverse)
options(tibble.width = Inf)
flights$na_count <- flights %>% is.na %>% rowSums
arrange(flights, desc(na_count))
Part of result:
I checked the help centre and this appears to be on topic though I know working code is often a candidate for code review.
Upvotes: 0
Views: 128
Reputation: 40171
Not sure whether much more efficient, however, you can rewrite it into:
flights %>%
arrange(desc(rowSums(is.na(.))))
Upvotes: 2