[R] Fetching datapoints from a Time Series
jim holtman
jholtman at gmail.com
Wed Oct 24 15:28:23 CEST 2007
> x <- read.table(tc <- textConnection(" Date Value
+ 01/03/05 -0.008471364
+ 01/04/05 -0.008153802
+ 01/05/05 -0.000780031
+ 01/06/05 -0.000130064
+ 01/07/05 -0.000650576
+ 01/08/05 -0.000130166
+ 01/10/05 -0.004174282
+ 01/11/05 0.01027384
+ 01/12/05 -0.006099558
+ 01/13/05 -0.009811054
+ 01/14/05 0.000657073"), header=TRUE)
> close(tc)
> y <- zoo(x[,2], as.Date(as.character(x[,1]), '%m/%d/%y'))
> y[index(y) >= as.Date('2005-01-02') & index(y) <= as.Date('2005-01-09')]
2005-01-03 2005-01-04 2005-01-05 2005-01-06 2005-01-07 2005-01-08
-0.008471364 -0.008153802 -0.000780031 -0.000130064 -0.000650576 -0.000130166
>
On 10/24/07, Megh Dal <megh700004 at yahoo.com> wrote:
> Hi all,
> I have a time series like that :
> Date Value
> 01/03/05 -0.008471364
> 01/04/05 -0.008153802
> 01/05/05 -0.000780031
> 01/06/05 -0.000130064
> 01/07/05 -0.000650576
> 01/08/05 -0.000130166
> 01/10/05 -0.004174282
> 01/11/05 0.01027384
> 01/12/05 -0.006099558
> 01/13/05 -0.009811054
> 01/14/05 0.000657073
>
> I import this dataset as a zoo object. Now I want to fetch the dataset between two particular dates. For example if I want to get data point between 01/02/05 and 01/09/05 I should get :
> 01/03/05 -0.008471364
> 01/04/05 -0.008153802
> 01/05/05 -0.000780031
> 01/06/05 -0.000130064
> 01/07/05 -0.000650576
> 01/08/05 -0.000130166
>
> Can anyone please tell me how to do that? Is there any function to do that?
> Regards,
>
>
> __________________________________________________
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list