[R] Warning: number of items to replace is not a multiple of replacement length
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Wed Sep 29 15:41:41 CEST 2004
Mag. Ferri Leberl wrote:
> What does this warning mean precisely?
When R replaces parts of a vector with another vector, it repeats the
replacing value until it is as long as the number of values it needs to
replace. For example:
> x = 1:10
> x[1:3]=1
- will do, effectively, x[1:3] = rep(1,3)
Now, if you replace with a vector that isn't an integer multiple of
the things being replaced, you get that error:
> x[1:3]=c(1,2)
Warning message:
number of items to replace is not a multiple of replacement length
Note that if it is an integer multiple, you don't get the error:
> x[1:6]=c(1,2)
but it repeats the (1,2) 3 times to fill the six places:
> x
[1] 1 2 1 2 1 2 7 8 9 10
> Is there any reason to care about it?
Yes, it usually means you've specified something wrong. What have you
done?
Baz
More information about the R-help
mailing list