One solution would be to strip the beginning characters (I've done this with a regex
but you might want to use substr
or simillar. Then matrix
into the required dimensions and return the column you want:
# regex to strip superfluous characters
# but `substring( txt , 10 )` would work just as well in this example
pat <- "^\\|M\\s+CHG\\s+\\d+\\s+(.*)\\|$"
x <- gsub( pat , "\\1" , txt )
# Get result
matrix( unlist( strsplit( x , "\\s+" ) ) , ncol = 2 , byrow = 2 )[,2]
# [1] "-1" "-1" "-1" "1" "1" "1"
The intermediate matrix
looks like this:
# [,1] [,2]
#[1,] "44" "-1"
#[2,] "48" "-1"
#[3,] "53" "-1"
#[4,] "63" "1"
#[5,] "64" "1"
#[6,] "65" "1"