'Break for loop in R
I have
sx <- structure(c(17, 11, 4, 0, 17, 11, 9, 15, 26, 12, 9, 0, 11, 9, 12, 5, 0, 9), .Dim = c(3L, 6L))
I need to break the value = 0. I used that function:
for (i in 1:ncol(sx)) {
for (j in 1:nrow(sx)) {
if (sx[j,i] == 0) {
break
}
else
{
sx[j,i] <- sx[j,i]
}
}
}
but it doesn't work. My expected output is
sx <- structure(c(17, 11, 4, 9, 17, 11, 12, 15, 26, 11, 9, 12, 9, 5, 9), .Dim = c(3L, 5L))
How can I do? Thx
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|