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
li
There is a base R function, quarters
, that more or less accomplishes what you want, though it prepends "Q". So
quarters(as.Date("2001-05-01"))
[1] "Q2"
If it is important to get rid of the "Q", you could use substr
substr(quarters(as.Date("2001-05-01")), 2, 2)
[1] "2"
Other date-related base R functions, such as weekdays
and months
can be found in help page ?quarters
.