[R] A simple question
Adams, Jean
jvadams at usgs.gov
Tue Jul 14 14:47:30 CEST 2015
R-help readers,
For your information ...
The package stringi is required to run Alex's code.
Alex's message was cross posted to StackOverflow, and seems to have been
answered there,
http://stackoverflow.com/questions/31398466/r-stri-locate-all-creating-a-start-and-end-matrix
Jean
On Tue, Jul 14, 2015 at 12:33 AM, Alex Kim via R-help <r-help at r-project.org>
wrote:
> Hello,
>
> I am trying to create a matrix that looks like this, using the
> stri_locate_all function.
>
> > x <- "ABCDJAKSLABCDAKJSABCD"
> > m <- stri_locate_all_regex(x, 'ABCD')
> > m
> [[1]]
> start end
> [1,] 1 4
> [2,] 10 13
> [3,] 18 21
>
> I tried converting m into a matrix, however it always seems to wrap around
> the wrong way:
>
> > output <- matrix(unlist(m), ncol = 2, byrow = TRUE)
> > output
> [,1] [,2]
> [1,] 1 10
> [2,] 18 4
> [3,] 13 21
>
> I want to output the start locations in the first column and the end
> locations in the second column into a matrix to look like this.
>
> [,1] [,2]
> [1,] 1 4
> [2,] 10 13
> [3,] 18 21
>
> Thank you for your help,
> Alex
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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