Joanna
Joanna

Reputation: 673

For loop warning in R: number of items to replace is not a multiple of replacement length

Here is my code and I am wondering why there are warning messages saying "number of items to replace is not a multiple of replacement length"?

for (i in 1:5) { 

if (i==1) {
Julian_data_first_expose[i]<-as.Date("2017-05-15") 
 }else{
Julian_data_first_expose[i]<-Julian_data_first_expose+365*(i-1)
 }
}

It seems work but I am curious about the warning messages.

Thanks!

Upvotes: 0

Views: 5619

Answers (1)

aku
aku

Reputation: 465

I think the problem may lie in Julian_data_first_expose+365*(i-1). This appears to return a vector, not a single value, is that what you intended? My guess at your intended code is Julian_data_first_expose[i] +365*(i-1)

Upvotes: 1

Related Questions