[R] Romoving elements from a vector. Looking for the opposite of c(), New user
jim holtman
jholtman at gmail.com
Thu Nov 15 19:28:15 CET 2007
You can also check out the 'set' operations: setdiff, intersect, union.
On Nov 15, 2007 12:08 PM, John Kane <jrkrideau at yahoo.ca> wrote:
> I think you've read Thomas's request in reverse. and
> what he want is:
> x[!x %in% z]
>
> Thanks for the %in% approach BTW.
>
> --- Charilaos Skiadas <cskiadas at gmail.com> wrote:
>
> >
> > On Nov 15, 2007, at 9:15 AM, Thomas Fr��jd
>
> wrote:
> >
> > > Hi
> > >
> > > I have three vectors say x, y, z. One of them, x
> > contains observations
> > > on a variable. To x I want to append all
> > observations from y and
> > > remove all from z. For appending c() is easily
> > used
> > >
> > > x <- c(x,y)
> > >
> > > But how do I remove all observations in z from x?
> > You can say I am
> > > looking for the opposite of c().
> >
> > If you are looking for the opposite of c, provided
> > you want to remove
> > the first part of things, then perhaps this would
> > work:
> >
> > z<-c(x,y)
> > z[-(1:length(x))]
> >
> > However, if you wanted to remove all appearances of
> > elements of x
> > from c(x,y), regardless of whether those elements
> > appear in the x
> > part of in the y part, I think you would want:
> >
> > z[!z %in% x]
> >
> > Probably there are other ways.
> >
> > Welcome to R!
> >
> > > Best regards
> >
> > Haris Skiadas
> > Department of Mathematics and Computer Science
> > Hanover College
> >
>
> ______________________________________________
> 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list