You seem to be a little confused. You are passing a matrix S
(which you haven't defined in the code you have posted here) to your function. That doesn't cause an error because inside your function you define a u
by v
matrix filled with NA
values (try matrix(,2,2)
to see), which overrides the value of S
passed in and triggers the error.
Try this:
Sip <- function(S,u,v){
for(i in 1:u)
{for(j in 1:v){
if(S[i,j]==S[j,i]){print("Simétrica")}
else{print("No simétrica")}
}
}
S
}
S <- matrix(1:4,2,2)
Sip(S,2,2)
## [1] "Simétrica"
## [1] "No simétrica"
## [1] "No simétrica"
## [1] "Simétrica"
## [,1] [,2]
## [1,] 1 3
## [2,] 2 4
That still might not be what you want, but it gets one step further ...
Also possibly useful:
apropos("symmetric")
isSymmetric(S)