由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - [R] a row of a matrix is not a matrix?
相关主题
R问题请教:如何从data frame按条件取出部分columnquestion about export sas figure into excel
问个r问题怎样用R定位变量的位置
如何用R处理大文件How to sort the columns in SAS?
[R]how to sample all possible continuous subset from ordered datasas code
please help on R subtable question !Help Please! SAS Advanced 考证题求助
双包子求教:SAS问题sas importing question
please help for the R code问2个sql left join的问题
请教一个proc transpose的问题怎么用SAS做加减乘除
相关话题的讨论汇总
话题: matrix话题: row话题: weiwei859话题: its话题: found
进入Statistics版参与讨论
1 (共1页)
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 的大作中提到】
: 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
5
g[2,,drop=F]
D******n
发帖数: 2836
6
great, This is what i want.

【在 T***y 的大作中提到】
: g[2,,drop=F]
1 (共1页)
进入Statistics版参与讨论
相关主题
怎么用SAS做加减乘除please help on R subtable question !
帮忙看看这个R程序,是怎样传递变量的?双包子求教:SAS问题
一个看着很简单sas的问题please help for the R code
如何把取值为1的column列出来?请教一个proc transpose的问题
R问题请教:如何从data frame按条件取出部分columnquestion about export sas figure into excel
问个r问题怎样用R定位变量的位置
如何用R处理大文件How to sort the columns in SAS?
[R]how to sample all possible continuous subset from ordered datasas code
相关话题的讨论汇总
话题: matrix话题: row话题: weiwei859话题: its话题: found