1

I am trying to delete some rows according to a filter.

clean <-function(z){
f <- z[!(z$"Current_status" == "T" & z$"Start_date" == 2012),]
return(f)
}

It worked on all dataframes but one. On this one, the lines I want to delete were fully emptied ("NA" value for each column) but the column remains. This is what I get:

     Current_status Start_date
1                 O       2005
2                 O       2004
3                 O       2004
4                 O       2002
5                 O       2002
NA             <NA>         NA
NA.1           <NA>         NA
8                 O          0
9                 O          0
10                O          0
11                O          0
NA.2           <NA>         NA

I tried several methods but none worked.

My hypothesis is that the problem is due to the fact that the number of the row changed and also became "NA".

How could I get rid of these rows?

Many thanks!

Jean
  • 13
  • 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) – Omniswitcher Jun 15 '22 at 09:31

1 Answers1

0

You could subset with the help of is.na():

f <- f[!is.na(f$Current_status) & !is.na(f$Start_date), ]
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360