[英]R: For loop is only executed once
Why is the following code only run once? 为什么以下代码只能运行一次?
for ( i in length( which( rowSums( m ) != 1 ) ) ) {
m[which( rowSums( m ) != 1 )[i], ncol( m )] <- 1
print(i)
}
m is matrix that contains values between 0 and 1 under the condition that the sum of each row can't exceed 1. m是在每行总和不能超过1的条件下包含0到1之间的值的矩阵。
It should be 1:length( which( rowSums( m ) != 1 ))
它应该是
1:length( which( rowSums( m ) != 1 ))
You want to iterate through a vector in your loop. 您想遍历循环中的向量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.