Q:

Sub-setting by partial date r

I am trying to find a way to subset a data.frame to only the records from a single month, but over multiple years (i.e. data from only April but years 1900, 1901, 1902, etc.).  I am putting the date information into a date class using the as.Date function.  Here is an example:
require("adehabitatHR")
data(teal)
Tdf <- teal
Tdf$date <- as.Date(Tdf$date, "%Y%m%d")

Now to subset it, I have tried setting the date equal to the month value both with and without using wildcards:
TdfFeb <- Tdf[Tdf$date == "*-02-*"]
TdfFeb <- Tdf[Tdf$date == "-02-"]

However, in both these situations I receive an error of: Error in charToDate(x): character string is not in a standard unambiguous format; this would suggest that R is not recognizing what I am inputting as a legitimate date format (I have also tried this with "/" and "." as opposed to "-"; all with the same outcome.
I have also tried setting it as a pattern
TdfFeb <- Tdf[Tdf$date == pattern = "-02-"]

Of course this does not work either, with an error due to the unexpected "=" after pattern.
I realize that for this particular data set, simply doing a date range would work since there is only data for February in 1901; however, as I said above, I would like to be able to pull out data over multiple years this way.  If anyone has encountered this before or has a suggestion I would appreciate the help.

A:

Since you have a valid date, you can extract the month using format.
month <- format(Tdf$date, format = "%m")

Tdf[month == "02", ]

               x        y       date
55851  5.9153319 45.44334 1901-02-01
57834  3.3944621 42.64384 1901-02-01
1917   9.9942731 43.42349 1901-02-01
58703  0.7046530 39.45739 1901-02-01
5673   3.2158674 41.60035 1901-02-01
...

