[R] Help regading time series data reading

Gabor Grothendieck ggrothendieck at gmail.com
Wed Sep 12 13:52:07 CEST 2007


Try using the zoo package like this:

Lines <- " Date                 PEG        ETN        HSP        PTC
13/10/2004        41.92        64.75        29.86        9.27
14/10/2004        41.93        61.79        29.98        9.14
15/10/2004        41.69        62.7        30.09        9.04
18/10/2004        41.37        62.14        30.39        8.96
19/10/2004        41.01        61.98        29.61        9.02
20/10/2004        41.01        61.98        30.25        9
"

Lines2 <- " Date       A       B
13/10/2004        64.75        29.86
15/10/2004        62.7        30.09
19/10/2004        61.98        29.61
"

library(zoo)
# replace with a line such as:
# z <- read.zoo("myfile.dat", header = TRUE, format = "%d/%m/%Y")
z <- read.zoo(textConnection(Lines), header = TRUE, format = "%d/%m/%Y")

# replace with a line such as:
# z <- read.zoo("myfile2.dat", header = TRUE, format = "%d/%m/%Y")
z2 <- read.zoo(textConnection(Lines2), header = TRUE, format = "%d/%m/%Y")

both <- merge(z, z2)  # this uses merge.zoo
plot(na.approx(both))


To learn more about zoo try:
  vignette("zoo")
  vignette("zoo-quickref")
and to learn about dates read the help desk in R News 4/1
by googling for CRAN News


On 9/11/07, Tolga Uzuner <tolga.uzuner at gmail.com> wrote:
> Dear R-Users,
>
> Have a question about reading in some data and manipulating dates. I
> have a data set in excel which looks like this:
>
> Date                 PEG        ETN        HSP        PTC
> 13/10/2004        41.92        64.75        29.86        9.27
> 14/10/2004        41.93        61.79        29.98        9.14
> 15/10/2004        41.69        62.7        30.09        9.04
> 18/10/2004        41.37        62.14        30.39        8.96
> 19/10/2004        41.01        61.98        29.61        9.02
> 20/10/2004        41.01        61.98        30.25        9
>
> I have used read.table by saving the sheety above in tab format to
> read this in but am
> having some difficulties:
> - the dates above do not seem to be getting read in in date format:
> how can I force this ?
> - I actually have two, and not one data set, and would like to
> synchronise them by date
> (exclude from both dates which are not in both): is there an easy way
> to do this ?
>
> Thanks,
> Tolga
>
> ______________________________________________
> 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