[R] Using grep

Erin Hodgess erinm.hodgess at gmail.com
Wed Oct 8 18:20:58 CEST 2008


Here is a possible solution:

> A
 [1] 200 201 202 203 204 205 206 207 208 209 210
> B
[1] 201 204 209
> which(!is.na(match(A,B)))
[1]  2  5 10
>

Hope this helps,
Sincerely,
Erin


On Wed, Oct 8, 2008 at 10:19 AM, mentor_ <mentor_ at gmx.net> wrote:
>
> Hi,
>
> I have a vector A with (200, 201, 202, 203, 204, ... 210) and a vector B
> with (201, 204, 209).
> Now I would like to get the position in vector A matches with the entries in
> vector B
> So what I want to have is the following result:
> [1] 2 5 10
>
> I tried the following:
> grep(B, A)
>
> grep(c(B), A)
>
> A <- as.character(A)
> B <- as.character(B)
>
> grep(B, A)
> grep(c(B), A)
>
> and several other combinations. But nothing is giving me the right result?!
> Does anyone know why?
>
> Cheers,
> Mentor
> --
> View this message in context: http://www.nabble.com/Using-grep-tp19881017p19881017.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodgess at gmail.com



More information about the R-help mailing list