Skip to content
Prev 247019 / 398506 Next

how to coerce part of each column of a matrix to a vector and merge them

Hello,

The answer to this one drops out of the answer to your previous question...

m <- matrix(1:16, nrow=4)
end <- c(2,3,1,3)
ii <- cbind(sequence(end), rep(1:length(end), end))
x <- m[ ii ]

Hope this helps,
Michael


2011/1/11 zhaoxing731 <zhaoxing731 at yahoo.com.cn>: