#Heterogeneous frequency -----------------------------
#create time series
ts1 <- TSERIES(1:10+0.000057,START=c(2000,1),FREQ=1)
ts2 <- TSERIES(1:11,START=c(2001,2),FREQ=12)
ts3 <- TSERIES(c(1:3,NA,9:19)+0.0023,START=c(2001,3),FREQ=4)
#create time series list
myList <- list(
myTitle1=ts1,
myTitle2=ts2,
myTitle3=ts3)
#define file path
filePath <- '~/temp.csv'
#export time series to csv then import back from csv
#export
BIMETS2CSV(
myList,
cellSeparator=';',
decimalSeparator=',',
dateFormat='%Y%m%d',
filePath=filePath,
overWrite=TRUE)
#import from csv
outList <- CSV2BIMETS(
filePath,
cellSeparator=';',
decimalSeparator=',',
dateFormat='%Y%m%d')
#compare input and output time series
for (idx in paste0('myTitle',1:3)) TABIT(myList[[idx]],outList[[idx]])
#Homogeneous frequency -----------------------------
#re-define time series, same frequency, different time range
ts1 <- TSERIES(1:10+0.000057,START=c(2000,1),FREQ=12)
ts2 <- TSERIES(1:11,START=c(2001,2),FREQ=12)
ts3 <- TSERIES(c(1:3,NA,9:19)+0.0023,START=c(2001,3),FREQ=12)
#create time series list
myList <- list(
myTitle1=ts1,
myTitle2=ts2,
myTitle3=ts3)
#define file path
filePath <- '~/temp.csv'
#export time series to csv then import from csv
#export with BIMETS2CSV and mergeList=TRUE
#note: argument in CSV2BIMETS is "mergedList"
BIMETS2CSV(
myList,
mergeList=TRUE,
cellSeparator=';',
decimalSeparator=',',
dateFormat='%Y%m%d',
filePath=filePath,
overWrite=TRUE)
outList <- CSV2BIMETS(filePath,
mergedList=TRUE,
cellSeparator=';',
decimalSeparator=',',
dateFormat='%Y%m%d')
#compare input and output time series
for (idx in paste0('myTitle',1:3)) TABIT(myList[[idx]],outList[[idx]])
#Impose user frequency -----------------------------
#create a monthly CSV file to be imported as a quarterly, i.e., FREQ_4
cat(c(
"FREQ_4,myTitle1,myTitle2",
"2001/01/31,NA,NA",
"2001/02/28,1,NA",
"2001/03/31,2,1.0023",
"2001/04/30,3,2.0023",
"2001/05/31,4,3.0023",
"2001/06/30,5,NA",
"2001/07/31,6,9.0023",
"2001/08/31,7,10.0023",
"2001/09/30,8,11.0023",
"2001/10/31,9,12.0023",
"2001/11/30,10,13.0023",
"2001/12/31,11,14.0023"
),
sep='\n',
file=filePath)
#import CSV
outList <- CSV2BIMETS(
filePath,
mergedList=TRUE)
#print quarterly series
TABIT(outList$myTitle1,outList$myTitle2)
#Automatic frequency retrieval -----------------------------
#create a quarterly CSV file with no frequency indication
cat(c(
"DATE,myTitle1,myTitle2",
"2001/03/31,2,1.0023",
"2001/06/30,5,NA",
"2001/09/30,8,11.0023",
"2001/12/31,11,14.0023"
),
sep='\n',
file=filePath)
#import CSV
outList <- CSV2BIMETS(
filePath,
mergedList=TRUE)
#print quarterly series
TABIT(outList$myTitle1,outList$myTitle2)
#Change locale -----------------------------
#set language to french
Sys.setlocale('LC_TIME','fr_FR.UTF8')
#export with BIMETS2CSV, full month names, and mergeList=TRUE
BIMETS2CSV(
myList,
mergeList=TRUE,
dateFormat='%Y %B %d',
filePath=filePath,
overWrite=TRUE)
#print file with french month names
cat(readLines(file(filePath)),sep='\n')
#read back file
outList <- CSV2BIMETS(
filePath,
dateFormat='%Y %B %d',
mergedList=TRUE)
#Custom TSRANGE, Title, missingString -----------------------------
#set language to US english
Sys.setlocale('LC_TIME','en_US.UTF8')
#define ts
ts1 <- TSERIES(1:10+0.000057,START=c(2000,1),FREQ=12)
#insert missing values
ts1[[c(2000,5),c(2000,7)]] <- NA
#set custom ts description
attributes(ts1)$MyDescription <- 'My Long Description'
#export to csv
BIMETS2CSV(
ts1,
dateFormat='%Y %B %d',
filePath=filePath,
overWrite=TRUE,
attributeOfNames='MyDescription',
missingString='.',
freqHeaderPrefix='MYFREQ_',
title="CSV TITLE")
#print file with custom settings
cat(readLines(file(filePath)),sep='\n')
#reimport in R
outList <- CSV2BIMETS(
filePath,
dateFormat='%Y %B %d',
filePath=filePath,
freqHeaderPrefix='MYFREQ_',
skipLines=1)
#print ts
TABIT(outList[['My Long Description']])
Run the code above in your browser using DataLab