Handling missing values in R

2019-09-23 07:12发布

问题:

I have the data as following

  Name   Location  profits loss sales    address      revenue  stocks
   AA     London     20      30    2    Lheigts,20109   54       45
   BB     Boston     NA      NA   NA    KicK,30029     NA        NA
   CC     Mumbai     NA      2     NA   New, 10023     43        NA

I would like to have output like this which will delete cases for which profits, loss, sales, revenue, stocks are completely missing. Any ideas?

   Name   Location  profits loss sales    address      revenue  stocks
   AA     London     20      30    2    Lheigts,20109   54        45
   CC     Mumbai     NA      2     NA   New, 10023     43        NA

回答1:

Try

 df1[rowSums(!is.na(df1[c(3:5,7:8)]))!=0,]