[R] which on array
asemeria@cramont.it
asemeria at cramont.it
Fri Apr 2 13:32:24 CEST 2004
Good morning !
Today I found a strange, for my poor knowledge of R, behaviour of
'which' on a matrix:
HAL9000> str(cluster.matrix)
num [1:227, 1:6300] 2 2 2 2 2 2 2 2 2 2 ...
HAL9000> class(cluster.matrix)
[1] "matrix"
HAL9000> ase <- cluster.matrix[1:5,1:5]
HAL9000> ase
[,1] [,2] [,3] [,4] [,5]
[1,] 2 2 2 0 -2
[2,] 2 2 2 0 -2
[3,] 2 2 2 0 -2
[4,] 2 2 2 0 -2
[5,] 2 2 2 0 -2
HAL9000> ase2 <- matrix(c(2,2,2,2,2)%*%t(c(1,1,1,0,-1)),5,5)
HAL9000> ase2
[,1] [,2] [,3] [,4] [,5]
[1,] 2 2 2 0 -2
[2,] 2 2 2 0 -2
[3,] 2 2 2 0 -2
[4,] 2 2 2 0 -2
[5,] 2 2 2 0 -2
HAL9000> str(ase2)
num [1:5, 1:5] 2 2 2 2 2 2 2 2 2 2 ...
But now:
HAL9000> which(ase2==-2,arr.ind=T)
row col
[1,] 1 5
[2,] 2 5
[3,] 3 5
[4,] 4 5
[5,] 5 5
HAL9000> which(ase==-2,arr.ind=T)
numeric(0)
which(ase=="-2",arr.ind=T)
row col
[1,] 1 5
[2,] 2 5
[3,] 3 5
[4,] 4 5
[5,] 5 5
May be the original matrix 'cluster.matrix' is not
properly a numerical matrix!? But 'str' say num[...] !!??
Some suggestion.
Tks!
A.S.
----------------------------
Alessandro Semeria
Models and Simulations Laboratory
Montecatini Environmental Research Center (Edison Group),
Via Ciro Menotti 48,
48023 Marina di Ravenna (RA), Italy
Tel. +39 544 536811
Fax. +39 544 538663
E-mail: alessandro.semeria at cramont.it
More information about the R-help
mailing list