[R] String match

jim holtman jholtman at gmail.com
Sat Jun 4 20:20:01 CEST 2016


try this:

> WhereToLook = c("ultracemco.bo.openam"   ,  "ultracemco.bo.higham"
+  ,"ultracemco.bo.lowam"   ,   "ultracemco.bo.closeam"   ,
+  "ultracemco.bo.volumeam"   ,"ultracemco.bo.adjustedam")
>
>  WhatToLook = c("volume", "close")
>
> # create pattern match
> pat <- paste(WhatToLook, collapse = "|")
> grep(pat, WhereToLook)
[1] 4 5




Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Sat, Jun 4, 2016 at 1:28 PM, Christofer Bogaso <
bogaso.christofer at gmail.com> wrote:

> Hi again,
>
> I am facing trouble to match a vector strings. Let say I have below
> full string vector
>
> WhereToLook = c("ultracemco.bo.openam"   ,  "ultracemco.bo.higham"
> ,"ultracemco.bo.lowam"   ,   "ultracemco.bo.closeam"   ,
> "ultracemco.bo.volumeam"   ,"ultracemco.bo.adjustedam")
>
> WhatToLook = c("volume", "close")
>
> Basically I need to find the positions of WhatToLook in WhereToLook.
> So my code goes as below :
>
> > pmatch(tolower(colnames(WhereToLook)), WhatToLook)
> integer(0)
>
>
> Although I was expecting my code would point 5 & 4 respectively.
>
> Appreciate if someone points as correct code for above case.
>
> Thanks,
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list