I have a datset where I have data from 1997 to 2009 and I want to subset the data according to date.
The code I have written is as follows:
creek <- read.csv("wolfcreek.csv")
library(ggplot2)
creek[1:10,]
colnames(creek) <- c("date","flow")
creek$date <- as.Date(creek$date, "%m/%d/%Y")
The code I used to create the subset is as follows:
creek1 <- subset(creek, as.Date(date) > (01-01-2000) & as.Date(date) <(01-01-2009))
But when I try to see the summary of creek1 I get
> creek1
[1] date flow
<0 rows> (or 0-length row.names)
Can anyone tell what I did wrong here ?
The dataset I used can be found on https://www.dropbox.com/s/eqpena3nk82x67e/creek.csv
Thank you so much.
Best Regards,
Jdbaba
No need to convert the column date, it is already in on the class Date.
Then you need to cretae dateMin, and dateMax coercing a string to a date.
Here I give the string in the right format, otherwise you need to use
format(like in @Mathew answer)Here, I would use package
xtsfor his fast subsetting and concise syntaxusing
quantmodfor example, It is time series so wee need to use the suitable package to treat it.Here I subset, and I plot (I zoom my time series)