[R] Warning: number of items to replace is not a multiple of replacement length

Jim Lemon bitwrit at ozemail.com.au
Thu Sep 30 13:11:45 CEST 2004

Mag. Ferri Leberl wrote:
> What does this warning mean precisely?
> Is there any reason to care about it?
> Can I Avoid it by another way of programming?

As you have already gotten most of your questions answered, here is a 
possible answer to the last. You may want to care about it, but not 
necessarily. I have had to use the recycling capability of R without knowing 
whether the length of the result would be a multiple of that of the source 
vector. Say I want to label a vector of daily observations, but I do not know 
which day the observations start or how many there are:

label.weekdays<-function(ndays,start=1) {

By creating a vector that is intentionally too long, then truncating it on 
one or both ends, I can recycle the source vector and avoid the warning.


More information about the R-help mailing list