missing value where TRUE/FALSE needed

laye

New Member
#1
hi,
i got this kind of error when my function is called : "missing value where TRUE/FALSE needed"
my fonction is :
Code:
exposition_1<-function(DAtdeb,DAtfin){
 
 
  ######## SANS SAUTS ########
  if (max(DAtdeb)< min(DAtfin)) {
    deb_exp=min(DAtdeb)
    fin_exp=max(DAtfin)
    
  }
 
 
  ################## TOUS LES AUTRES CAS AVEC SAUTS #####################
  else {
    deb_exp=DAtdeb
    fin_exp=DAtfin
    
  }
 
  res=return(cbind(deb_exp,fin_exp))
 
}
Can you help me to find the mistakes

Merci
 
Last edited:

Dason

Ambassador to the humans
#3
It's hard to say anything without a reproducible example because if the inputs are valid it should work although I'm not really sure why you want to do what your code does and it would be better with better indentation.

So yeah give some example input where it breaks. The error is basically saying that the condition in the if clause is missing instead of numeric. Figure out what's causing that in your data.
 

laye

New Member
#4
the idea of the code is to determine the period of presence of an insured according to the date of the beginning and the end of his contracts.
Knowing that an insured can have multiple contracts, I test whether there is an overlap or not.
I want to keep the maximum period if there is overlap.
Datdeb and Datfin are size vectors (contract number)
Datdeb = start of contract and Datfin = end of contract
The code is indented.
Thanks you
 

Dason

Ambassador to the humans
#5
That's cool. I still don't have a reproducible example where it's failing for you though. Take a look at your inputs when you get a case where it fails and see what min(whatever) and max(thatotherthing) look like. If they aren't what you're expecting then investigate why.