[R] gregexpr() - length of the matched text to a vector

Ben Bolker bolker at ufl.edu
Wed Jan 11 15:49:52 CET 2006


Petri Palmu <petri.palmu <at> geneos.fi> writes:


> I'm using gregexpr(). As a result something like this:
> 
> # starting positions of the match:
> [[1]]
> [1] 7 18
> 
> # length of the matched text:
> attr(,"match.length")
> [1] 4 4
> 
> Now, I'd like to have a matrix,
>   7    4
> 18   4
> 


  something like
 x1 = gregexpr("iss",c("mississippi"))
 x2 = rbind(x1[[1]],attr(x1[[1]],"match.length"))
 x2
     [,1] [,2]
[1,]    2    5
[2,]    3    3




More information about the R-help mailing list