Learn R Programming

tframePlus (version 2024.2-1)

TSwriteXLS: Write Time Series to an .xls Spreadsheet File

Description

Write one or more time series to a .xls spreadsheet file

Usage

TSwriteXLS(x, ..., FileName="R.xls", SheetNames=NULL,
               dateHeader="date", verbose = FALSE)
    TSwriteCSV(x, FileName="R.csv",  dateFormat=1, dateHeader="date")

Value

logical

Arguments

x

a time series or matrix of time series.)

...

additional time series objects (like x).

FileName

a string to use for the file name.

SheetNames

Logical indicating if NA should be removed from the beginning and end of a series.

dateFormat

an integer indicating the format to use for dates. (See details.)

dateHeader

string or vector of strings to use as header on date column.

verbose

logical passed to WriteXLS.

Details

This functions uses WriteXLS to write time series data to an .xls spreadsheet file. If the object x has mulitple series then they will be put on the same sheet. Additional objects in ... will be put on additional pages.

The first line of each sheet will have column headers using seriesNames from the series in the column. The first column will have dates and the heading for that column will be determined by dateHeader. This can be a vector of length equal the number of sheets, of a single character string, in which case it is replicated for each sheet. The dateHeader is a might be useful for indication information like the date of the last observation in a known place on the sheet (A1) for indicating on a graph. For convenience, the year, period, and a character representation of the period are indicated in columns 2 to 4. This is followed by columns of the data.

If SheetNames is NULL (the default) then the sheet names will be generated from the first series name in each object. If SheetNames is supplied then it should have an element for x and for each object in ....

If WriteXLS does not find a version of perl with appropriate modules then a work around is attempted using save.

WriteCSV handles only a single object x which can have mulitple series. These are wtten as columns in the comma separated value file. dateFormat can be 0 indicating no date, 1 indicating a format like "Jan 1969", 2 indicating a format like 1969,1, or 3 indicating a format like 1969,"Jan",. Only 0 or 1 are supported for data other than monthly and quarterly frequencies.

See Also

WriteXLS

Examples

Run this code
 tofile <- tempfile()
 
 z <- ts(1:10, start=c(1999,2), freq=12)
 seriesNames(z) <- "ser 1"
 TSwriteXLS(z, FileName=tofile) 

 zz <- tbind(z, diff(z))
 seriesNames(zz) <- c("ser 1", "diff")
 TSwriteXLS(zz, FileName=tofile,  SheetNames="2 series")

 zz <- ts(1:10, start=c(1999,1), freq=1)
 seriesNames(zz) <- "annual ser"
 TSwriteXLS(z, zz, FileName=tofile,  SheetNames=c("monthly", "annual"))

 unlink(tofile) 

Run the code above in your browser using DataLab