由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 用R出现怪问题。
相关主题
R:matrixsas question。
【R】关于R的variable typeHow to avoid if statement in R
请帮忙: 怎么从R object 里取一列数据。这个R程序能帮改进一下吗?
【R】保留matrix中某些值沮丧 R
data clustering by vector correlation distance更新一下Taste of R,再问两个R的问题。
another sas questionR question about apply() and outer()
R help[合集] 昨天专门比较了python和R的 运行速度。
关于处理两个csv文件交集和子集的问题【包子】从excel读取数据到R的问题
相关话题的讨论汇总
话题: true话题: component话题: attributes话题: null话题: v1
进入Statistics版参与讨论
1 (共1页)
q**j
发帖数: 10612
1
我的矩阵是
> S
V1 V2 V3 V4 V5 V
6
[1,] 1.8220e-04 -4.6245e-06 2.2056e-05 -1.0127e-04 -1.7530e-04 4.4493e-0
6
[2,] -4.6245e-06 1.8543e-05 -8.6882e-06 4.2653e-06 4.4493e-06 -1.7840e-0
5
[3,] 2.2056e-05 -8.6882e-06 1.2833e-05 -1.5716e-05 -2.1221e-05 8.3591e-0
6
[4,] -1.0127e-04 4.2653e-06 -1.5716e-05 5.9286e-05 9.7431e-05 -4.1037e-0
6
[5,] -1.7530e-04 4.4493e-06 -2.1221e-05 9.7431e-05 2.4952e-04 -6.3331e-0
6
[6,] 4.4493e-06 -1.7840e-05 8.3591e-06 -4.1037e-06 -6.3331e-06 2.5393e-0
5
[7,] -2.1221e-05 8.3591e-06 -1.2346e-05 1.5121e-05 3.0205e-05 -1.1898e-0
5
[8,] 9.7431e-05 -4.1037e-06 1.5121e-05 -5.7040e-05 -1.3868e-04 5.8411e-0
6
[9,] 5.1305e-06 -1.3022e-07 6.2107e-07 -2.8515e-06 3.2183e-06 -8.1685e-0
8
[10,] -1.3022e-07 5.2213e-07 -2.4465e-07 1.2010e-07 -8.1685e-08 3.2753e-0
7
[11,] 6.2107e-07 -2.4465e-07 3.6134e-07 -4.4254e-07 3.8959e-07 -1.5346e-0
7
[12,] -2.8515e-06 1.2010e-07 -4.4254e-07 1.6694e-06 -1.7887e-06 7.5339e-0
8
V7 V8 V9 V10 V11 V1
2
[1,] -2.1221e-05 9.7431e-05 5.1305e-06 -1.3022e-07 6.2107e-07 -2.8515e-0
6
[2,] 8.3591e-06 -4.1037e-06 -1.3022e-07 5.2213e-07 -2.4465e-07 1.2010e-0
7
[3,] -1.2346e-05 1.5121e-05 6.2107e-07 -2.4465e-07 3.6134e-07 -4.4254e-0
7
[4,] 1.5121e-05 -5.7040e-05 -2.8515e-06 1.2010e-07 -4.4254e-07 1.6694e-0
6
[5,] 3.0205e-05 -1.3868e-04 3.2183e-06 -8.1685e-08 3.8959e-07 -1.7887e-0
6
[6,] -1.1898e-05 5.8411e-06 -8.1685e-08 3.2753e-07 -1.5346e-07 7.5339e-0
8
[7,] 1.7573e-05 -2.1523e-05 3.8959e-07 -1.5346e-07 2.2667e-07 -2.7760e-0
7
[8,] -2.1523e-05 8.1189e-05 -1.7887e-06 7.5339e-08 -2.7760e-07 1.0472e-0
6
[9,] 3.8959e-07 -1.7887e-06 1.1393e-05 -2.8917e-07 1.3792e-06 -6.3323e-0
6
[10,] -1.5346e-07 7.5339e-08 -2.8917e-07 1.1595e-06 -5.4328e-07 2.6671e-0
7
[11,] 2.2667e-07 -2.7760e-07 1.3792e-06 -5.4328e-07 8.0242e-07 -9.8274e-0
7
[12,] -2.7760e-07 1.0472e-06 -6.3323e-06 2.6671e-07 -9.8274e-07 3.7072e-0
6
> S==t(S)
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12
[1,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[2,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[3,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[4,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[5,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[6,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[7,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[8,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[9,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[10,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[11,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[12,] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
>
但是
> all.equal(S, t(S))
[1] "Attributes: < Component 2: Component 1: target is NULL, current is char
acter >"
[2] "Attributes: < Component 2: Component 2: Modes: character, NULL >"

[3] "Attributes: < Component 2: Component 2: Lengths: 12, 0 >"

[4] "Attributes: < Component 2: Component 2: target is character, current is
NULL >"
这个很奇怪。明明是对称矩阵,为什么R的all.equal function不喜欢我的S呢?请大侠
指点。
q**j
发帖数: 10612
2
好像是rownames和column names不一样造成的。这个也太不合理了吧。
> colnames(S)=1:12
> rownames(S)=1:12
> all.equal(S, t(S))
[1] TRUE
请问有没有简单的办法让R不这么变态。明明是个矩阵么。

V
-0
-0
-0
-0

【在 q**j 的大作中提到】
: 我的矩阵是
: > S
: V1 V2 V3 V4 V5 V
: 6
: [1,] 1.8220e-04 -4.6245e-06 2.2056e-05 -1.0127e-04 -1.7530e-04 4.4493e-0
: 6
: [2,] -4.6245e-06 1.8543e-05 -8.6882e-06 4.2653e-06 4.4493e-06 -1.7840e-0
: 5
: [3,] 2.2056e-05 -8.6882e-06 1.2833e-05 -1.5716e-05 -2.1221e-05 8.3591e-0
: 6

b*****n
发帖数: 685
3
colnames()=NULL
rownames()=NULL
q**j
发帖数: 10612
4
你试试就知道了。这个不行。

【在 b*****n 的大作中提到】
: colnames()=NULL
: rownames()=NULL

l*********s
发帖数: 5409
5
I tried, it works

【在 q**j 的大作中提到】
: 你试试就知道了。这个不行。
q**j
发帖数: 10612
6
sorry, i was wrong. this works. i tried it again. but this still seems to be
very strange, or imperfect, right?

【在 l*********s 的大作中提到】
: I tried, it works
l*********s
发帖数: 5409
7
I think it is a natural assumption that different names imply different objects.

be

【在 q**j 的大作中提到】
: sorry, i was wrong. this works. i tried it again. but this still seems to be
: very strange, or imperfect, right?

q**j
发帖数: 10612
8
it is a matrix. why does matrix need names for rows and columns? R is trying
to be too smart here.

objects.

【在 l*********s 的大作中提到】
: I think it is a natural assumption that different names imply different objects.
:
: be

l*********s
发帖数: 5409
9
maybe because you derived the matrix from data frame and column names are
preserved?

trying

【在 q**j 的大作中提到】
: it is a matrix. why does matrix need names for rows and columns? R is trying
: to be too smart here.
:
: objects.

q**j
发帖数: 10612
10
yes. that is what happened. so the as.matrix() function should trip those
names automatically.

【在 l*********s 的大作中提到】
: maybe because you derived the matrix from data frame and column names are
: preserved?
:
: trying

l*********s
发帖数: 5409
11
better not, as usually you want to coerce it back to a data frame down the
road.

【在 q**j 的大作中提到】
: yes. that is what happened. so the as.matrix() function should trip those
: names automatically.

s*******t
发帖数: 2896
12
all(S==t(S))

V
-0
-0
-0

【在 q**j 的大作中提到】
: 我的矩阵是
: > S
: V1 V2 V3 V4 V5 V
: 6
: [1,] 1.8220e-04 -4.6245e-06 2.2056e-05 -1.0127e-04 -1.7530e-04 4.4493e-0
: 6
: [2,] -4.6245e-06 1.8543e-05 -8.6882e-06 4.2653e-06 4.4493e-06 -1.7840e-0
: 5
: [3,] 2.2056e-05 -8.6882e-06 1.2833e-05 -1.5716e-05 -2.1221e-05 8.3591e-0
: 6

l*********s
发帖数: 5409
13
good to learn new command!

【在 s*******t 的大作中提到】
: all(S==t(S))
:
: V
: -0
: -0
: -0

1 (共1页)
进入Statistics版参与讨论
相关主题
【包子】从excel读取数据到R的问题data clustering by vector correlation distance
an R questionanother sas question
如何给一个matrix的rownames起个名字name?R问题求教!R help
SAS 中 proc iml 怎么生成data file?关于处理两个csv文件交集和子集的问题
R:matrixsas question。
【R】关于R的variable typeHow to avoid if statement in R
请帮忙: 怎么从R object 里取一列数据。这个R程序能帮改进一下吗?
【R】保留matrix中某些值沮丧 R
相关话题的讨论汇总
话题: true话题: component话题: attributes话题: null话题: v1