Displaying 1 result from an estimated 1 matches for "secondpartm".
2009 Aug 10
2
strsplit a matrix
...succinctly and efficiently as
possible.
I've tried such things as sapply(matrix, strsplit, "-") and tried to go
from there, but I can't figure it out! So far I do it with a 2D for loop
which can't be efficient!
firstPartM <- matrix(ncol= dim(zzz)[2], nrow= dim(zzz)[1])
secondPartM <- matrix(ncol= dim(zzz)[2], nrow= dim(zzz)[1])
for(i in 1:dim(zzz)[1]) {
for(j in 1:dim(zzz)[2]) {
splitS <- strsplit(zzz[i,j],"-")
firstPartM[i,j] <- splitS[[1]][1]
secondPartM[i,j] <- splitS[[1]][2]
}
}
Cheers,
Jim