What do you mean by "compare"?
In the two examples you give, it seems like you are trying to
"compare"
one cell with its adjacent neighbor in the next column, its adjacent
neighbor in the next row, and its diagonally adjacent neighbor in the next
column and row. Is that right?
If I correctly understand the neighbors you are interested in comparing,
and I make the assumption that the comparison you are making is the
difference in the two values, then something like this might help.
m <- scan()
277.4 276.24 275.62 276.55 278.05
277.4 276.24 275.55 276.42 277.72
277.4 276.24 275.50 276.22 277.39
277.4 276.24 275.42 276.02 277.02
277.4 276.22 275.37 275.82 276.64
a <- matrix(m, byrow=T, nrow=5)
a
compare <- function(mat, i, j) {
c1 <- mat[i, j] - mat[i, j+1]
c2 <- mat[i, j] - mat[i+1, j+1]
c3 <- mat[i, j] - mat[i+1, j]
c(c1, c2, c3)
}
compare(a, 1, 1)
compare(a, 1, 2)
Jean
`·.,, ><(((º> `·.,, ><(((º> `·.,, ><(((º>
Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409 USA
From:
kokavolchkov <kokavolchkov@gmail.com>
To:
r-help@r-project.org
Date:
08/05/2011 07:17 AM
Subject:
[R] R compare cells in one matrix
Sent by:
r-help-bounces@r-project.org
Good morning!
Please, could you help me with the problem?
I have a matrix *144x73.*
An example of a matrix:
[,1] [,2] [,3] [,4] [,5]
[1,] 277.4 276.24 275.62 276.55 278.05
[2,] 277.4 276.24 275.55 276.42 277.72
[3,] 277.4 276.24 275.50 276.22 277.39
[4,] 277.4 276.24 275.42 276.02 277.02
[5,] 277.4 276.22 275.37 275.82 276.64
And I want to *compare*its cells like this:
a11 and a12;
a11 and a21;
a11 and a22.
then
a12 and a22;
a12 and a13;
a12 and a23.
and so on in a cycle.
*Is there a function or a package that can be used for comparation?*
Thank you!
--
View this message in context:
http://r.789695.n4.nabble.com/R-compare-cells-in-one-matrix-tp3720854p3720854.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]