On Mon, May 12, 2003 at 03:47:33AM +0200, Wojtek Musial
wrote:> I lese gro?e Zeitreihen in R ein z.B. mit:
[ Please note that the language on this list is English ]
> disc hat dann folgende Struktur:
>
> > disc[1:5]
>
> V1 V2
> 1 01/03/1955 1.5
> 2 01/04/1955 1.5
> 3 01/05/1955 1.5
> 4 01/06/1955 1.5
> 5 01/07/1955 1.5
>
> ich will das disc als Zeitreihe erkannt wird und will z.B 01/03/1955 in ein
> Datum verwandeln, aber es wird als factor aufgefasst:
>
> > disc[1,1]
> [1] 01/03/1955
> 17647 Levels: 01/01/1956 01/01/1957 01/01/1958 01/01/1959 ... 12/31/2002
There are several ways to do this. One way is to parse a date with strptime:
> datevec <-
c("01/03/1955","01/04/1955","01/05/1955")
> strptime(datevec, format="%m/%d/%Y")
[1] "1955-01-03" "1955-01-04" "1955-01-05"
The return values from strptime are genuine POSIXlt time objects which you
can transform or compute on in very powerful ways. There is quite a bit of
documentation to master, though. Start with help(DateTimeClasses) and look
for more examples in the mailing list archives. There are lots of them.
If you then want to do time-series statistics (such as ARIMA models, say),
you need to create ts() objects. The POSIXlt (or POSIXct) types are not used
for that, and the main restriction is that dates need to be in regular
increments. Working with daily data has its challenges. Adrian has the
beginnings of an irregular time series class in the most recent tseries
package.
Hth, Dirk
--
Don't drink and derive. Alcohol and algebra don't mix.