[R] Names in vector occurring in another vector

jim holtman jholtman at gmail.com
Mon Apr 16 20:31:36 CEST 2007


Try this:

> mainnames<-c("CAD","AUD")
>
> checknames<-c("CAD.l1","AUD.l1","JPY.l1","EUR.l1","CAD.l2","AUD.l2","JPY.l2","EUR.l2")
>
> x.match <- grep(paste(mainnames, collapse="|"), checknames)
> x.match
[1] 1 2 5 6
> checknames[-x.match]
[1] "JPY.l1" "EUR.l1" "JPY.l2" "EUR.l2"
>


On 4/16/07, Leeds, Mark (IED) <Mark.Leeds at morganstanley.com> wrote:
> I have a vector of character strings such as
>
> mainnames<-c("CAD","AUD") and another vector say
>
> checknames<-c("CAD.l1","AUD.l1","JPY.l1","EUR.l1","CAD.l2","AUD.l2","JPY
> .l2","EUR.l2")
>
> I want a new vector of character strings that is just
> resultnames<-c("JPY.l1","EUR.l1","JPY.l2","EUR.l2")
>
> Because any time a name occurs in checknames that has a subset that
> matches with mainnames, the
> name in checknames should not be in the final result !!!!!!!!!!!!!!!!!
>
> I can't use %in% because this example doesn't require exact matching.
> The general problem would always have an  "el after the dot but the
> numbers can go upto double digits.
> Thanks a lot.
>
>
>
> mark
> --------------------------------------------------------
>
> This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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