[R] simplier way to import txt time-series data

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jun 8 00:09:37 CEST 2006


Try this which reads in the data as a data frame and appends a
chron variable datetime:

Lines <- "YYYY MM DD HH  data1  data2
2002 12 01 01 0.002 0.003"

DF <- read.table(textConnection(Lines), header = TRUE)
library(chron)
DF$datetime <- with(DF, chron(paste(MM, DD, YYYY, sep = "/")) + HH/24)
DF

On 6/7/06, Jan Schwanbeck <jansc at gmx.net> wrote:
> Hello much more experienced R-users,
>
> I have got a txt - file which contains data formated like this:
>
> YYYY MM DD HH  data1  data2 ... data31
> 2002 12 01 01 0.002 0.003 ... 312.0
>
> The single columns are divided by at least one space.
>
> Is their an easy and fast way to make R understand that the first 4
> columns are year month day and hour  to recognize it as time series data.
>
> The time series are not complete. Single hours could be missing.
>
> Thanks a lot for answering my question. I just cannot believe that it is
> a big problem for R to handle this clean format while it even imports
> data from excel-files.
>
> Greatings
>
> Jan
>
> ______________________________________________
> 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
>



More information about the R-help mailing list