While listing it like that is it possible to remove the rows that has same row and col numbers?
Like..
1 1 x
2 2 x2
....
Regards,
Kumaraguru
On Jan 28, 2011, at 9:23 AM, Petr PIKAL <petr.pikal at precheza.cz> wrote:
Hi
KumaraGuru <kumaragurutp at gmail.com> napsal dne 28.01.2011 17:03:50:
I want to melt the cor matrix and form a 3 col matrix with row# col# and
cor.
Well, in that case it will be probably better to transform it to data
frame and use melt. Or you can drop dimensions of this matrix and generate
proper sequences of row and column numbers. Try it with smaller matrix.
Row names does not matter
x<-matrix(1:12, 4,4)
row.names(x)<-letters[1:4]
colnames(x)<-letters[1:4]
x
a b c d
a 1 5 9 1
b 2 6 10 2
c 3 7 11 3
d 4 8 12 4
[1] 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4
cbind(rep(1:4, 4), rep(1:4, each=4), x)
x
[1,] 1 1 1
[2,] 2 1 2
[3,] 3 1 3
[4,] 4 1 4
[5,] 1 2 5
[6,] 2 2 6
[7,] 3 2 7
[8,] 4 2 8
[9,] 1 3 9
[10,] 2 3 10
[11,] 3 3 11
[12,] 4 3 12
[13,] 1 4 1
[14,] 2 4 2
[15,] 3 4 3
[16,] 4 4 4
This I m using to draw a graph.
Regards,
Kumaraguru
On Jan 28, 2011, at 6:47 AM, Petr PIKAL <petr.pikal at precheza.cz> wrote:
Hi
r-help-bounces at r-project.org napsal dne 28.01.2011 09:52:05:
What makes matrix to print V1, V2 as the row and col indices instead
numbers??
cdata = read.table("ramesh.txt") #cdata is read from a file.
c1 = cor(cdata)
I am printing c1 below. I need only numbers. I dont need V1,
V2 0.9471591 1.0000000 0.8888108 0.9108174 0.9703906 0.9425248
V3 0.9191233 0.8888108 1.0000000 0.8788107 0.9077245 0.9078971
V4 0.9403129 0.9108174 0.8788107 1.0000000 0.9477058 0.9017977
V5 0.9689690 0.9703906 0.9077245 0.9477058 1.0000000 0.9531459
V6 0.9621362 0.9425248 0.9078971 0.9017977 0.9531459 1.0000000
V7 0.9529811 0.9294308 0.8965331 0.8646251 0.9162016 0.9447130
V8 0.9167526 0.9395067 0.8491496 0.8942693 0.9460702 0.9304229
V9 0.9512951 0.9598302 0.8666839 0.9465725 0.9645178 0.9486105
V10 0.9551633 0.9040160 0.9180022 0.9429816 0.9448644 0.9220875
0.9075537
Vn are names of columns which R gave to your matrix when you read it
data frame. And cor just makes a matrix of pairwise corelation
coefficients from this data frame conveniently named from this data
If you do not want those names just unname it.
c1 = unname(cor(cdata))
But I wonder why you dislike those names which are, well, just names.
Regards
Petr
--
View this message in context:
row-col-indices-instead-of-numbers-tp3243980p3243980.html
Sent from the R help mailing list archive at Nabble.com.