R number of items to replace is not a multiple of replacement length / results however correct
which()
can return a vector if there are multiple matches. For example:
which((1:12)%%2 == 0) # which are even?
Is matrix$col_b[i]
unique? The results may still look correct. Notice what happens in this case:
x <- 1:2
x[1] <- 3:4
x
Also, 1:b-1
does not give you the numbers from 1
to b - 1
but the number from 1
to b
, all minus 1
:
b <- 10
1:b-1
You need parentheses to force the subtraction first: 1:(b - 1)
.