[R] Dropping rows conditionally

Lazarus Mramba LMramba at kilifi.kemri-wellcome.org
Thu Mar 5 07:18:03 CET 2009


Dear R-help team,

I am getting addicted to using R but keep on getting many challenges on the way especially on data management (data cleaning).

I have been wanting to drop all the rows if there values are  `NA' or have specific values like 1 or 2 or 3.


mdat <- matrix(1:21, nrow = 7, ncol=3, byrow=TRUE,
               dimnames = list(c("row1", "row2","row3","row4","row5","row6","row7"),
                               c("C.1", "C.2", "C.3")))
mdat<-data.frame(mdat)
mdat

      C.1 C.2 C.3
row1   1   2   3
row2   4   5   6
row3   7   8   9
row4  10  11  12
row5  13  14  15
row6  16  17  18
row7  19  20  21

I want to say drop row if value=1 or value =11 or value =20

How do I do that?


Kind regards,
Lazarus Mramba
Junior Statistician
P.O Box 986, 80108,
Kilifi, Kenya
Mobile No. +254721292370
Tel: +254 41 522063
Tel: +254 41 522390
(office extension : 419)

This e-mail (including any attachment to it) contains information
which is confidential. It is intended only for the use of the named
recipient. If you have received this e-mail in error, please let us know
by replying to the sender, and immediately delete it from your system.
Please note, that in these circumstances, the use, disclosure,
distribution or copying of this information is strictly prohibited. We
apologize for any inconvenience that may have been caused to you.
KEMRI-Wellcome Trust Programmecannot accept any responsibility for the accuracy
or completeness of this message as it has been transmitted over a public
network. KEMRI-Wellcome Trust Programme reserves the right to monitor all incoming and
outgoing email traffic. Although the Programme has taken reasonable
precautions to ensure no viruses are present in emails, it cannot
accept responsibility for any loss or damage arising from the use of the
email or attachments. Any views expressed in this message are those of
the individual sender, except where the sender specifically states them
to be the views of KEMRI- Wellcome Trust Programme".




More information about the R-help mailing list