title: Extract only quarter from a date in r
body: <p>I would like to extract ONLY the quarter from a date, e.g., to get an integer 1 from the date "2003-02-08". I have been trying something along this line</p>
  
  <pre><code>library(mondate)
  as.yearqtr(dat$DATE)
  </code></pre>
  
  <blockquote>
    <p>"2003 Q1"</p>
  </blockquote>
  
  <pre><code>as.character(as.yearqtr(dat$DATE))[1]
  </code></pre>
  
  <blockquote>
    <p>"2003 Q1"</p>
  </blockquote>
  
  <p>which hasn't been giving my desired result. Of course I can write conditions as follows</p>
  
  <pre><code>library(data.table)
  data$DATE = as.Date(data$DATE, format='%d%b%Y')
  data$month=month(data$DATE)
  setDT(data)[month==1,  quarter:=1]  
      ...
  </code></pre>
  
  <p>This will work, but is not elegant at all. Is there a more beautiful way of doing this?</p>
  
  <p>Thank you lmo and user2100721! I really wish I could accept all of the answers! </p>