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.
It should be 1:length( which( rowSums( m ) != 1 ))
You want to iterate through a vector in your loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.