| selectByDate | R Documentation |
Utility function to filter a data frame by a date range or specific date periods (month, year, etc.). All options are applied in turn, meaning this function can be used to select quite complex dates simply.
selectByDate(
mydata,
start = NULL,
end = NULL,
year = NULL,
month = NULL,
day = NULL,
hour = NULL
)
mydata |
A data frame containing a |
start |
A start date or date-time string in the form d/m/yyyy, m/d/yyyy, d/m/yyyy HH:MM, m/d/yyyy HH:MM, d/m/yyyy HH:MM:SS, m/d/yyyy HH:MM:SS, yyyy-mm-dd, yyyy-mm-dd HH:MM or yyyy-mm-dd HH:MM:SS. |
end |
See |
year |
A year or years to select e.g. |
month |
A month or months to select. Can either be numeric e.g. |
day |
A day name or or days to select. |
hour |
An hour or hours to select from 0-23 e.g. |
David Carslaw
## select all of 1999
data.1999 <- selectByDate(mydata, start = "1/1/1999", end = "31/12/1999 23:00")
head(data.1999)
tail(data.1999)
# or...
data.1999 <- selectByDate(mydata, start = "1999-01-01", end = "1999-12-31 23:00")
# easier way
data.1999 <- selectByDate(mydata, year = 1999)
# more complex use: select weekdays between the hours of 7 am to 7 pm
sub.data <- selectByDate(mydata, day = "weekday", hour = 7:19)
# select weekends between the hours of 7 am to 7 pm in winter (Dec, Jan, Feb)
sub.data <- selectByDate(mydata,
day = "weekend", hour = 7:19, month =
c("dec", "jan", "feb")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.