1

I would like to remove all rows with 3 or more NA values - below is an example of my data set (but the actual data set has 95,000 rows)

Plot_ID  Tree_ID   Dbh13   Dbh08  Dbh03  Dbh93_94
106       6         236     132    123     132    
204       5         NA      NA     NA      142
495       8         134     NA     NA      102
984       12        NA      123    110     97

So that it looks like this

Plot_ID  Tree_ID   Dbh13   Dbh08  Dbh03  Dbh93_94
  106       6         236     132    123     132    
  495       8         134     NA     NA      102
  984       12        NA      123    110     97
isabelnt
  • 91
  • 1
  • 6

1 Answers1

4
Plot_ID  Tree_ID   Dbh13   Dbh08  Dbh03  Dbh93_94
106       6         236     132    123     132    
204       5         NA      NA     NA      142
495       8         134     NA     NA      102
984       12        NA      123    110     97

df1    <- read.table(con<-file("clipboard"),header=T)

cnt_na <- apply(df1, 1, function(z) sum(is.na(z)))

df1[cnt_na < 3,]
  Plot_ID Tree_ID Dbh13 Dbh08 Dbh03 Dbh93_94
1     106       6   236   132   123      132
3     495       8   134    NA    NA      102
4     984      12    NA   123   110       97
Hack-R
  • 22,422
  • 14
  • 75
  • 131