mardi 16 juillet 2019

R missing value where TRUE/FALSE needed

I'm running the following code in R, but I'm getting the error
<< missing value where TRUE/FALSE needed >>

Could you help me?

ref <- c(0, 50, 80, 150, 200, 300) dat <- NULL

for (i in 1:length(ref)) { for (j in 1:nrow(file)) { if ((file$RefDate_start[j]>ref[i]) & (file$RefDate_end[j]<ref[i])) { dat[j]<-file$amount[j]
} else
dat[j]<-0 } file[,paste0("amount", i)] <- dat }

How can I identify what causes the error?

Aucun commentaire:

Enregistrer un commentaire