tom soyer
2007-Apr-12 18:38 UTC
[R] Construct time series objects from raw data stored in csv files
Hi, I have time series data stored in csv files (see below for an example of the data). I understand that in order to analyze my data in R, I need to first transform it into a ts object. Howeve, I could not find an example on how exactly to do that. Is ts the only function I need? What are the steps that I need to go through to build a time series object from raw data like this? Thanks, Tom ----------------------------------- DATE,VALUE 1921-01-01,19.000 1921-02-01,18.400 1921-03-01,18.300 1921-04-01,18.100 1921-05-01,17.700 1921-06-01,17.600 1921-07-01,17.700 1921-08-01,17.700 1921-09-01,17.500 1921-10-01,17.500 1921-11-01,17.400 1921-12-01,17.300 1922-01-01,16.900 1922-02-01,16.900 1922-03-01,16.700 1922-04-01,16.700 1922-05-01,16.700 1922-06-01,16.700 1922-07-01,16.800 1922-08-01,16.600 1922-09-01,16.600 1922-10-01,16.700 1922-11-01,16.800 1922-12-01,16.900 [[alternative HTML version deleted]]
Achim Zeileis
2007-Apr-12 18:52 UTC
[R] Construct time series objects from raw data stored in csv files
On Thu, 12 Apr 2007, tom soyer wrote:> Hi, > > I have time series data stored in csv files (see below for an example of the > data). I understand that in order to analyze my data in R, I need to first > transform it into a ts object. Howeve, I could not find an example on how > exactly to do that. Is ts the only function I need? What are the steps that > I need to go through to build a time series object from raw data like this?With the "zoo" package you can do library("zoo") z <- read.zoo("yourdata.csv", sep = ",") plot(z) See vignette("zoo", package = "zoo") for more information and also some more details about other time series classes. Z> Thanks, > > Tom > > ----------------------------------- DATE,VALUE > 1921-01-01,19.000 > 1921-02-01,18.400 > 1921-03-01,18.300 > 1921-04-01,18.100 > 1921-05-01,17.700 > 1921-06-01,17.600 > 1921-07-01,17.700 > 1921-08-01,17.700 > 1921-09-01,17.500 > 1921-10-01,17.500 > 1921-11-01,17.400 > 1921-12-01,17.300 > 1922-01-01,16.900 > 1922-02-01,16.900 > 1922-03-01,16.700 > 1922-04-01,16.700 > 1922-05-01,16.700 > 1922-06-01,16.700 > 1922-07-01,16.800 > 1922-08-01,16.600 > 1922-09-01,16.600 > 1922-10-01,16.700 > 1922-11-01,16.800 > 1922-12-01,16.900 > > [[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. > >
Gabor Grothendieck
2007-Apr-12 19:26 UTC
[R] Construct time series objects from raw data stored in csv files
On 4/12/07, tom soyer <tom.soyer at gmail.com> wrote:> Hi, > > I have time series data stored in csv files (see below for an example of the > data). I understand that in order to analyze my data in R, I need to first > transform it into a ts object. Howeve, I could not find an example on how > exactly to do that. Is ts the only function I need? What are the steps that > I need to go through to build a time series object from raw data like this? >Try pasting this into an R session: Lines.raw <- "DATE,VALUE 1921-01-01,19.000 1921-02-01,18.400 1921-03-01,18.300 1921-04-01,18.100 1921-05-01,17.700 1921-06-01,17.600 1921-07-01,17.700 1921-08-01,17.700 1921-09-01,17.500 1921-10-01,17.500 1921-11-01,17.400 1921-12-01,17.300 1922-01-01,16.900 1922-02-01,16.900 1922-03-01,16.700 1922-04-01,16.700 1922-05-01,16.700 1922-06-01,16.700 1922-07-01,16.800 1922-08-01,16.600 1922-09-01,16.600 1922-10-01,16.700 1922-11-01,16.800 1922-12-01,16.900 " library(zoo) # replace next line with something like this: # z <- read.zoo("myfile.dat", header = TRUE, sep = ",") z <- read.zoo(textConnection(Lines.raw), header = TRUE, sep = ",") time(z) <- as.yearmon(time(z)) as.ts(z)
Maybe Matching Threads
- Regression in strptime
- perform Kruskal-Wallis test without using the built-in command in R
- Problem with strptime generating missing values where none appear to exist
- package zoo, function na.spline with option maxgap -> Error: attempt to apply non-function?
- Regression in strptime