r - 对包含 19 个暗淡 50*50 矩阵的 4 个数组应用 if-else 条件
问题描述
我有 4 个 50*50 矩阵,我想使用 if-else 来获得 4 组二进制矩阵。现在,如果我想应用一系列阈值,那么我遇到了问题。
请看以下代码:
X <- mvrnorm(n=50, mu = rep(0, 50), Sigma = matrix(1,50,50)+diag(50))
p1<- nrow(X)
threshold <- seq(from = 5, to = 95, by = 5)
array1<-array(0,c(p1,p1,length(threshold)))
array2<-array(0,c(p1,p1,length(threshold)))
array3<-array(0,c(p1,p1,length(threshold)))
array4<-array(0,c(p1,p1,length(threshold)))
criteria1 <- t(X)%*%X
criteria2 <- t(X)+X
criteria3 <- sqrt(t(X)%*%X)
criteria4 <- (t(X)+X)/2
for (i in 1:length(threshold)) {
array1[,,i] <- ifelse( criteria1 <threshold[i],0,1)
array2[,,i] <- ifelse( criteria2 <threshold[i],0,1)
array3[,,i] <- ifelse( criteria3 <threshold[i],0,1)
array4[,,i] <- ifelse( criteria4 <threshold[i],0,1)
}
Error in array4[, , i] <- ifelse(criteria2 < threshold[i], 0, 1) :
incorrect number of subscripts
解决方案
推荐阅读
- ghostscript - 如何使用 ghostscript 将 PDF 转换为 PDF/A-1a?转换成PDF/A-1a需要什么条件?
- php - 如何在 Api-Platform 中手动将资源序列化为 Json?
- sql - 如何通过在 SQL Server 中对单个列进行区分来获得表的所有列?
- javascript - 无法通过 sequelize.authenticate() 方法使用异步等待
- oracle - ORA-02315: 默认构造函数的参数数量不正确
- javascript - 如何在JS中的时间轴图表中对标签进行分组
- python - 无法将 bigquery.QueryJobConfig() 中的 default_dataset 设置为字符串
- swift - 从 iCloud 下载的 Swift AVAsset 在 iOS 14 上没有权限:错误代码=257
- python - 在Django中获取上个月的第一个和最后一个日期
- c# - “本地编译失败。.Net 无法加载运行时程序集”
.dll'." 的长度为 85,在 "Loc" 附近不同(索引 0)