【发布时间】:2020-04-20 20:20:01
【问题描述】:
我尝试测试矩阵是否对称,但这不起作用。
> View(new.function)
> View(new.function)
> new.function <- function(a){
+ for(i in 1:nrow(a)){
+ for(j in 1:ncol(a)){
+ if(a==t(a)){
+ print("true")
+ }else{print("false")}
+ }
+ }
+ }
> a <- matrix(1:3,3,3)
> a
[,1] [,2] [,3]
[1,] 1 1 1
[2,] 2 2 2
[3,] 3 3 3
> new.function(a)
[1] "true"
[1] "true"
[1] "true"
[1] "true"
[1] "true"
[1] "true"
[1] "true"
[1] "true"
[1] "true"
【问题讨论】:
-
isSymmetric(a, check.attributes = FALSE)
标签: r matrix user-defined-functions symmetric