0

What's the best formula to delete rows where an row has NA value?

will this work?

all_trips_v2 <- all_trips_v2 %>% 
  filter(!(ride_length = "NA"))

Want to delete all rows where ride_length = NA

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • 2
    Does this answer your question? [Remove rows with all or some NAs (missing values) in data.frame](https://stackoverflow.com/questions/4862178/remove-rows-with-all-or-some-nas-missing-values-in-data-frame) – Nad Pat Oct 12 '21 at 14:36

2 Answers2

0

In your example, the filter should be...

new_df <- all_trips_v2 %>%
   filter(!is.na(ride_length))

EDIT: A filter doesn't necessarily 'delete' rows. Also, "NA" in quotes, a character string, is not the same as an NA as in...no value.

TTS
  • 1,818
  • 7
  • 16
0

You should remove the paranthesis around "NA", otherwise you will match the character pattern "NA" not actual NAs. You may look at the functions na.omit(), complete.cases() or is.na() - so something like filter(!is.na(ridge_length))

OliverHennhoefer
  • 677
  • 2
  • 8
  • 21