Remove the missing data in the file

I want to remove all missing data in the file.
I tried na.omit, however, the error shows could not found the function"na.omit".
How can I solve this problem?
Or is there any other way that I can remove all missing number in the file?

Thanks in advance.

Hi, and welcome!

If you're working with a data frame, here's one way to do it

suppressPackageStartupMessages(library(dplyr)) 
dat <- structure(list(x = c(23234L, 23461L, 25644L, 25824L, 24287L, 
25454L, 23849L, 23221L, NA, NA, NA, NA, NA, NA), y = c(362L, 
427L, 550L, 530L, 453L, 353L, 226L, 223L, NA, NA, NA, NA, NA, 
NA)), row.names = 2717:2730, class = "data.frame")
dat
#>          x   y
#> 2717 23234 362
#> 2718 23461 427
#> 2719 25644 550
#> 2720 25824 530
#> 2721 24287 453
#> 2722 25454 353
#> 2723 23849 226
#> 2724 23221 223
#> 2725    NA  NA
#> 2726    NA  NA
#> 2727    NA  NA
#> 2728    NA  NA
#> 2729    NA  NA
#> 2730    NA  NA
dat %>% filter(!is.na(x) & !is.na(y))
#>       x   y
#> 1 23234 362
#> 2 23461 427
#> 3 25644 550
#> 4 25824 530
#> 5 24287 453
#> 6 25454 353
#> 7 23849 226
#> 8 23221 223

Created on 2020-02-25 by the reprex package (v0.3.0)

You can also use tidyr::drop_na() is a little more straight forward

library(tidyverse)

dat <- data.frame(
   row.names = c("2717","2718","2719","2720","2721",
                 "2722","2723","2724","2725","2726","2727","2728","2729",
                 "2730"),
           x = c(23234L,23461L,25644L,25824L,24287L,
                 25454L,23849L,23221L,NA,NA,NA,NA,NA,NA),
           y = c(362L,427L,550L,530L,453L,353L,226L,
                 223L,NA,NA,NA,NA,NA,NA)
)

dat %>% 
    drop_na()
#>          x   y
#> 2717 23234 362
#> 2718 23461 427
#> 2719 25644 550
#> 2720 25824 530
#> 2721 24287 453
#> 2722 25454 353
#> 2723 23849 226
#> 2724 23221 223
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.