Good day, I need to subset a data by removing several rows. I know the %in% operator, i.e. sub <- mydata[group %in% c("A","B","E","G"), ] What I need is the opposite, that is remove rows and/or columns. What is the operator for "NOT IN"? I tried (i)! %in% and (ii) ^%in% and both resulted in a "could not find function" error. Kind Regards Emily Deomano | Biometrician BSES Limited | ABN 29 103 760 005 | PO Box 86 | 50 Meiers Road | Indooroopilly Q 4068 Australia P: +61 7 3331 3304 | M: +61 408 656 452 | F: +61 7 3871 0383 | E: edeomano@bses.com.au<mailto:edeomano@bses.com.au> | W: bses.com.au -------------------- Internet e-Mail Disclaimer -------------------- PRIVILEGED - PRIVATE AND CONFIDENTIAL: This email and any files transmitted with it are intended solely for the use of the addressee(s) and may contain information, which is confidential or privileged. If you are not the intended recipient, be aware that any disclosure, copying, distribution, or use of the contents of this information is prohibited. In such case, you should destroy this message and kindly notify the sender by reply e-mail. The views and opinions expressed in this e-mail are those of the sender and do not necessarily reflect the views of the company. VIRUSES: Email transmission cannot be guaranteed to be secure or error free, as information may be intercepted, corrupted, lost, destroyed, arrive late or incomplete or contain viruses. This email and any files attached to it have been checked with virus detection software before transmission. You should nonetheless carry out your own virus check before opening any attachment. BSES Limited does not represent or warrant that files attached to this email are free from computer viruses or other defects and accepts no liability for any loss or damage that may be caused by software viruses [[alternative HTML version deleted]]
Put the "!" in front of the whole expression, not just the %in% function. I.e. sub <- mydata[!(mydata$group %in% c("A", "B", "E", "G")),] Christian On Thu, 2010-10-07 at 09:17 +1000, Emily Deomano wrote:> Good day, > I need to subset a data by removing several rows. I know the %in% operator, i.e. > > sub <- mydata[group %in% c("A","B","E","G"), ] > > What I need is the opposite, that is remove rows and/or columns. What is the operator for "NOT IN"? I tried (i)! %in% and (ii) ^%in% and both resulted in a "could not find function" error. > > > Kind Regards > > Emily Deomano | Biometrician > BSES Limited | ABN 29 103 760 005 | PO Box 86 | 50 Meiers Road | Indooroopilly Q 4068 Australia > P: +61 7 3331 3304 | M: +61 408 656 452 | F: +61 7 3871 0383 | E: edeomano at bses.com.au<mailto:edeomano at bses.com.au> | W: bses.com.au > > > -------------------- Internet e-Mail Disclaimer -------------------- > > PRIVILEGED - PRIVATE AND CONFIDENTIAL: This email and any files transmitted with it are intended solely for the use of the addressee(s) and may contain information, which is confidential or privileged. If you are not the intended recipient, be aware that any disclosure, copying, distribution, or use of the contents of this information is prohibited. In such case, you should destroy this message and kindly notify the sender by reply e-mail. The views and opinions expressed in this e-mail are those of the sender and do not necessarily reflect the views of the company. > > VIRUSES: Email transmission cannot be guaranteed to be secure or error free, as information may be intercepted, corrupted, lost, destroyed, arrive late or incomplete or contain viruses. This email and any files attached to it have been checked with virus detection software before transmission. You should nonetheless carry out your own virus check before opening any attachment. BSES Limited does not represent or warrant that files attached to this email are free from computer viruses or other defects and accepts no liability for any loss or damage that may be caused by software viruses > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On Oct 6, 2010, at 9:03 PM, Christian Raschke wrote:> Put the "!" in front of the whole expression, not just the %in% > function. I.e. > > sub <- mydata[!(mydata$group %in% c("A", "B", "E", "G")),]You can also look at the match help page where %in% and its negation, %w/o% , are illustrated. -- David.> > Christian > > On Thu, 2010-10-07 at 09:17 +1000, Emily Deomano wrote: >> Good day, >> I need to subset a data by removing several rows. I know the %in% >> operator, i.e. >> >> sub <- mydata[group %in% c("A","B","E","G"), ] >> >> What I need is the opposite, that is remove rows and/or columns. >> What is the operator for "NOT IN"? I tried (i)! %in% and (ii) ^%in >> % and both resulted in a "could not find function" error. >> >> >> Kind Regards >> >> Emily Deomano | Biometrician >> BSES Limited | ABN 29 103 760 005 | PO Box 86 | 50 Meiers >> Road | Indooroopilly Q 4068 Australia >> P: +61 7 3331 3304 | M: +61 408 656 452 | F: +61 7 3871 0383 >> | E: edeomano at bses.com.au<mailto:edeomano at bses.com.au> | W: >> bses.com.au >> >> >> -------------------- Internet e-Mail Disclaimer -------------------- >> >> PRIVILEGED - PRIVATE AND CONFIDENTIAL: This email and any files >> transmitted with it are intended solely for the use of the >> addressee(s) and may contain information, which is confidential or >> privileged. If you are not the intended recipient, be aware that >> any disclosure, copying, distribution, or use of the contents of >> this information is prohibited. In such case, you should destroy >> this message and kindly notify the sender by reply e-mail. The >> views and opinions expressed in this e-mail are those of the sender >> and do not necessarily reflect the views of the company. >> >> VIRUSES: Email transmission cannot be guaranteed to be secure or >> error free, as information may be intercepted, corrupted, lost, >> destroyed, arrive late or incomplete or contain viruses. This email >> and any files attached to it have been checked with virus detection >> software before transmission. You should nonetheless carry out your >> own virus check before opening any attachment. BSES Limited does >> not represent or warrant that files attached to this email are free >> from computer viruses or other defects and accepts no liability for >> any loss or damage that may be caused by software viruses >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD West Hartford, CT
Try !(group %in% C("A", ...)) A slightly cuter way is to define your own operator.> `%ni%` <- Negate(`%in%`) > letters[1:3] %ni% letters[3:5][1] TRUE TRUE FALSE>________________________________________ From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Emily Deomano [EDeomano at bses.com.au] Sent: 07 October 2010 09:17 To: r-help at r-project.org Subject: [R] what is the "NOT IN" operator Good day, I need to subset a data by removing several rows. I know the %in% operator, i.e. sub <- mydata[group %in% c("A","B","E","G"), ] What I need is the opposite, that is remove rows and/or columns. What is the operator for "NOT IN"? I tried (i)! %in% and (ii) ^%in% and both resulted in a "could not find function" error. Kind Regards Emily Deomano | Biometrician BSES Limited | ABN 29 103 760 005 | PO Box 86 | 50 Meiers Road | Indooroopilly Q 4068 Australia P: +61 7 3331 3304 | M: +61 408 656 452 | F: +61 7 3871 0383 | E: edeomano at bses.com.au<mailto:edeomano at bses.com.au> | W: bses.com.au -------------------- Internet e-Mail Disclaimer -------------------- PRIVILEGED - PRIVATE AND CONFIDENTIAL: This email and any files transmitted with it are intended solely for the use of the addressee(s) and may contain information, which is confidential or privileged. If you are not the intended recipient, be aware that any disclosure, copying, distribution, or use of the contents of this information is prohibited. In such case, you should destroy this message and kindly notify the sender by reply e-mail. The views and opinions expressed in this e-mail are those of the sender and do not necessarily reflect the views of the company. VIRUSES: Email transmission cannot be guaranteed to be secure or error free, as information may be intercepted, corrupted, lost, destroyed, arrive late or incomplete or contain viruses. This email and any files attached to it have been checked with virus detection software before transmission. You should nonetheless carry out your own virus check before opening any attachment. BSES Limited does not represent or warrant that files attached to this email are free from computer viruses or other defects and accepts no liability for any loss or damage that may be caused by software viruses [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.