[R] A simple question

Alex Kim alexkim205 at yahoo.com
Tue Jul 14 07:33:17 CEST 2015


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]]



More information about the R-help mailing list