Hi All,
I am trying to create a function which evaluates whether the values (which
are equal to one) of a matrix are the same as their mirror values. Consider
the following matrix:
> n<-matrix(cbind(c(0,1,1),c(1,0,0),c(0,1,0)),3,3)
> colnames(n)<-cbind("A","B","C");rownames(n)<-cbind("A","B","C")
> n
A B C
A 0 1 0
B 1 0 1
C 1 0 0
Hence, since n[2,1] and n[1,2] are 1 and the same, the function should
return the name of the row of n[2,1]. I used the following function:
for (i in length(rownames(n))) {
for (j in length(colnames(n))){
if(n[i,j]==n[j,i]){
rownames(n)[[i]]->output} else {}
}
}
> output
NULL
The right answer would have been "B", though. I simply do not see my
mistake. I am very greatful for suggestions.
Thank you.
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.