One way, using base
R would be to make sure your dates are of class Date
or similar ( e.g. POSIXct) if you haven't already, and then to extract the months and years (as your data spans more than one year) and aggregate like so:
# Convert to date if not already
df1$X1 <- as.Date(df1$X1)
# Get months
df1$Month <- months(df1$X1)
# Get years
df1$Year <- format(df1$X1,format="%y")
# Aggregate 'X2' on months and year and get mean
aggregate( X2 ~ Month + Year , df1 , mean )
# Month Year X2
#1 December 09 0.0000000
#2 February 10 0.1714286
#3 January 10 1.2074074
There are quite a few ways of doing this if you have a look around.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…