Re: [R] strsplit a matrix

2009-08-10 Thread Jun Shen
Henrique, This is a very nice approach. I wonder what if I have data like 2-172-45 and want to break it down into three parts 2, 172 and 45. How do we use your method to achieve it? Thanks. Jun On Mon, Aug 10, 2009 at 12:34 PM, Henrique Dallazuanna wrote: > Try this: > > #1 > gsub(".*-", "", zz

Re: [R] strsplit a matrix

2009-08-10 Thread Henrique Dallazuanna
Try this: #1 gsub(".*-", "", zzz) #2 gsub("-.*", "", zzz) #3) gsub(".*-(.*)-.*", "\\1", zzz) On Mon, Aug 10, 2009 at 4:20 PM, Jun Shen wrote: > Henrique, > > This is a very nice approach. I wonder what if I have data like 2-172-45 > and want to break it down into three parts 2, 172 and 45. Ho

Re: [R] strsplit a matrix

2009-08-10 Thread Henrique Dallazuanna
Try this: #1 gsub(".*-", "", zzz) #2 gsub("-.*", "", zzz) On Mon, Aug 10, 2009 at 1:56 PM, James Perkins wrote: > Dear all, > > I am trying to split a matrix into 2 as efficiently as possible. > > It is a character matrix: > > 1 2 3 1 "2-271" "2-367" "1-79" > 2 "2-282" "2-378"

Re: [R] strsplit a matrix

2009-08-10 Thread Dimitris Rizopoulos
one way us the following: mat <- rbind( c("2-271", "2-367", "1-79"), c("2-282", "2-378", "1-90"), c("2-281", "2-377", "1-89") ) sp <- strsplit(c(mat), "-") mat1 <- sapply(sp, "[", 1) mat2 <- sapply(sp, "[", 2) dim(mat1) <- dim(mat2) <- dim(mat) mat1 mat2 I hope it helps. Best, Dim