Calculating calendar year for a student based on DOB I've written this brief function for calculating which calendar year a student would be in Year 1 based on their DOB (date of birth). In 1998 there was a change in the DOB cut points for starting Year 1, hence the need for a function. 

year1 &lt;- function(x){
    if(x &lt;= as.Date("1996-12-31")) {out &lt;- as.numeric(format(x, "%Y")) +6}
    if(x &gt;= as.Date("1997-07-01")) {ifelse(as.numeric(format(x, "%m")) &gt;=07 , out &lt;- as.numeric(format(as.Date(x), "%Y")) + 7, out &lt;- as.numeric(format(x, "%Y")) + 6)} 
    if(x &gt;= as.Date("1997-01-01") &amp; x &lt;= as.Date("1997-06-30")) {out &lt;- 2003}
    return(out)
}


An example of the results:

&gt; year1(as.Date("1996-02-15"))
[1] 2002
&gt; year1(as.Date("1999-02-15"))
[1] 2006


I plan to run it like this:

&gt; test &lt;- c(as.Date("1985-09-15"),as.Date("1999-02-15"),as.Date("2004-08-15"))
&gt; sapply(test,year1)
[1] 1991 2006 2011


I have a lot of data to run this over, and the use of so many ifs and assigning the result to out just to write it seems pretty redundant, but I couldn't think of a better way to do it.
I think this is equivalent to your function.

year1 &lt;- function(dob) as.numeric(format(dob, "%Y")) + 6 +
    (as.Date("1997-07-01") &lt;= dob &amp; 7 &lt;= as.numeric(format(dob, "%m")))


You would run it like this.

&gt; test &lt;- c(as.Date("1985-09-15"),as.Date("1999-02-15"),as.Date("2004-08-15"))
&gt; year1(test)