D******n 发帖数: 2836 | 1 R is driving me crazy, a row of a matrix is not a matrix any more. Its a
vector. If you force it to be a matrix it becomes a column matrix, not a row
matrix......
> g<-matrix(1:9,3)
> g
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> g[2,]
[1] 2 5 8
> as.matrix(g[2,])
[,1]
[1,] 2
[2,] 5
[3,] 8
Found solution with subset function. But is there any better way to do it? | w*******9 发帖数: 1433 | 2 So why do you need it to be a matrix? Most of the time the vector is enough.
Did you try the transpose function t()? | D******n 发帖数: 2836 | 3 Think of it as a changing matrix in a for loop
for example
for (i in 1:100000) {
....
mat <- AA[rows,cols]
....
}
so sometimes mat will collapse into a one row matrix or a one column matrix
or a one cell matrix. You want mat to be always a "matrix" so that u can
write generic code to handle mat.
enough.
【在 w*******9 的大作中提到】![](/moin_static193/solenoid/img/up.png) : So why do you need it to be a matrix? Most of the time the vector is enough. : : Did you try the transpose function t()?
| D**u 发帖数: 288 | 4 weiwei859 is right
>t(as.matrix(g[2,]))
[,1] [,2] [,3]
[1,] 2 5 8 | T***y 发帖数: 43 | | D******n 发帖数: 2836 | 6 great, This is what i want.
【在 T***y 的大作中提到】![](/moin_static193/solenoid/img/up.png) : g[2,,drop=F]
|
|