简体   繁体   中英

Subset daily time series data by month

How I can select all days time series of a month from the following data-frame:

time <- data.frame(seq(as.Date("1985-05-01"), as.Date("2014-05-31"), by = "day")) 

I tried this but did not work:

Mays.Decs <- time[months(time(time), TRUE) %in% c("Dec", "May")]

This approach involves including a name for the 'date' column, and using that column to subset, similarly to how you have in your question.

# Add variable name for date column
time <- data.frame(date = seq(as.Date("1985-05-01"), as.Date("2014-05-31"), by = "day")) 

# Subset 
time[months(time$date) %in% c("December", "May"),]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM