title: Unused argument error in nested ifelse statements
body: <p>I'm making a function that outputs the day of the week, given a number of days since 1/1/1970. The function worked fine when it was a chain of <code>if then</code> statements, but I want to use the function on vectors, so I've needed to build this silly looking chain of <code>ifelse</code> statements.</p>
  
  <p>Unfortunately, I keep getting this error:</p>
  
  <pre><code>Error in ifelse(rem == 0, day = "Thursday", ifelse(rem == 1, day = "Friday",  : 
  unused argument(s) (day = "Thursday")
  Calls: dayFinder -&gt; ifelse
  Execution halted
  </code></pre>
  
  <p>I haven't been able to figure out how to get around it - it looks like it's simply ignoring the <code>then</code> part of the <code>ifelse</code> statement. I've tried feeding it a variety of sample data sets or data points and haven't been able to fix the error.</p>
  
  <p>Here is my code - thanks in advance.</p>
  
  <pre><code>dayFinder &lt;- function(x){
  #Assuming that '0' refers to January 1 1970
  #Store given number
  start &lt;- x
  #Initialize variable
  day="Halloween"
  #Divide x by 7 and store remainder
  rem &lt;- x%%7
  #Determine the day
  ifelse(rem==0, day="Thursday", 
      ifelse (rem==1, day="Friday", 
          ifelse (rem==2, day="Saturday", 
              ifelse (rem==3, day="Sunday", 
                  ifelse (rem==4, day="Monday", 
                      ifelse(rem==5, day="Tuesday", 
                          if (rem==6)
                              {
                                  day="Wednesday"
                                  }))))))
  return(day)
  }
  
  q = seq(7,50,1)
  z = dayFinder(q)
  z
  </code></pre>