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 :
> Hello
>
> Suppose I have a matrix mat=(1:16,2)
>
Hello
Suppose I have a matrix mat=(1:16,2)
[,1] [,2] [,3] [,4]
[1,]159 13
[2,]26 10 14
[3,]37 11 15
[4,]48 12 16
there is a vector end=c(2,3,1,3)
#coerce the 1st 2 numbers of the 1st column to a vector [1] 1 2
#coerce the 1st 3 numbers of
2 matches
Mail list logo