[R] Using grep
Doran, Harold
HDoran at air.org
Wed Oct 8 18:22:00 CEST 2008
A <- seq(200,210,1)
B <- c(201,204,209)
which(A %in% B)
> -----Original Message-----
> From: r-help-bounces at r-project.org
> [mailto:r-help-bounces at r-project.org] On Behalf Of mentor_
> Sent: Wednesday, October 08, 2008 11:19 AM
> To: r-help at r-project.org
> Subject: [R] Using grep
>
>
> 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.
>
More information about the R-help
mailing list