Re: [R] A question about POSIXct

From: Michael Sumner <mdsumner_at_utas.edu.au>
Date: Fri, 04 May 2007 06:23:20 +1000


Hello,

It seems that "danish" is a numeric vector with attributes attached - the attribute vector is POSIXct and is the same length as danish.

You can create this from a data frame like this:

 x <- data.frame(Date = ISOdate(2007, 5, 1:10), Value = rnorm(10)) str(x)
'data.frame': 10 obs. of 2 variables:  $ Date :'POSIXct', format: chr "2007-05-01 12:00:00" "2007-05-02 12:00:00" "2007-05-03 12:00:00" "2007-05-04 12:00:00" ...  $ Value: num 1.891 0.741 -0.368 1.701 -0.660 ...

 xx <- x$Value
attr(xx, "times") <- x$Date
str(xx)
 atomic [1:10] 0.0414 -0.7124 -1.2976 0.3101 0.4343 ...

HTH Cheers, Mike.

> Dear List:
>
> I have a simple two-column data set in .csv format, with the first column
> being the date and second column being some value. I use read.csv() to
> import the data as follows:
>
>
>
> x <- read.csv("myfile.csv",header=T, dec=".", colClasses=c(Date="POSIXct"))
>
>
>
> The structure of x is:
>
>
>
> > str(x)
>
> `data.frame': 2959 obs. of 2 variables:
>
> $ Date:'POSIXct', format: chr "1998-01-01" "1998-01-01" "1998-01-01"
> "1998-01-01" ...
>
> $ Value: num 0.07379 0.07181 0.01555 0.00630 0.00688 ...
>
>
>
> This is not what I want. Instead, I want the structure to be the same as
> that of the following data set:
>
>
>
> > str(danish)
>
> atomic [1:2167] 1.68 2.09 1.73 1.78 4.61 ...
>
> - attr(*, "times")='POSIXct', format: chr [1:2167] "1980-01-02 18:00:00"
> "1980-01-03 18:00:00" "1980-01-04 18:00:00" "1980-01-06 18:00:00" ...
>
>
>
> "danish" is a data set that the package "evir" comes with.
>
>
> Any help would be appreciated.
>
> [[alternative HTML version deleted]]
>
>



R-help_at_stat.math.ethz.ch 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. Received on Thu 03 May 2007 - 21:34:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 May 2007 - 23:31:51 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.