[R] How to setup the tsp attribute of a dataset
Gabor Grothendieck
ggrothendieck at gmail.com
Sat Nov 21 00:05:56 CET 2009
The first two components of the tsp vector are in time units as
mentioned in ?tsp . Thus you would want:
> x <- 1:100
> tsp(x) <- c(1, 25.75, 4)
but normally you don't have to set it explicitly in the first place.
Just use ts:
> x <- 1:100
> x.ts <- ts(x, start = 1, frequency = 4)
> tsp(x.ts)
[1] 1.00 25.75 4.00
> x.ts
Qtr1 Qtr2 Qtr3 Qtr4
1 1 2 3 4
2 5 6 7 8
3 9 10 11 12
4 13 14 15 16
5 17 18 19 20
6 21 22 23 24
7 25 26 27 28
8 29 30 31 32
9 33 34 35 36
10 37 38 39 40
11 41 42 43 44
12 45 46 47 48
13 49 50 51 52
14 53 54 55 56
15 57 58 59 60
16 61 62 63 64
17 65 66 67 68
18 69 70 71 72
19 73 74 75 76
20 77 78 79 80
21 81 82 83 84
22 85 86 87 88
23 89 90 91 92
24 93 94 95 96
25 97 98 99 100
On Fri, Nov 20, 2009 at 5:53 PM, Samik Raychaudhuri <samikr at gmail.com> wrote:
> Hello,
> I am wondering how I should set up the tsp attribute (available through
> attr(x, "tsp")) of a dataset x? Let's assume that x has 100 points, and I
> want to set the frequency to 4.
> I tried:
>> attr(x,"tsp")<-c(1,100,4)
> Error in attr(x, "tsp") <- c(1, 100, 4) :
> invalid time series parameters specified
> Is there any other way to set the frequency of the data?
> Thanks.
> -Samik
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list