Import Raw Data as dataframe,xts and ts from Bank of Japan. Case:Monthly data

Import Raw Data as dataframe,xts and ts from Bank of Japan. Case:Monthly data
-
```{r,message=F,error=F,warning=F}
library(xts)
cnt<-0
df.data<-list()
xts.data<-list()
ts.data<-list()
username<-Sys.info()['user']
folder.name<-c("BOJdata")
path<-paste("C:/Users/",username,"/Desktop",sep="")
folder.path<-file.path(path,folder.name)
if(file.exists(folder.path)==F){dir.create(folder.path)}
setwd(folder.path)
for(fff in 1:length(dir(folder.path))){
tmp<-read.csv(file=dir(folder.path)[fff],header=T,as.is=T,skip=2,na.strings=c("", "NA"))
tmp<-tmp[-c(1:11),]
tmp[,1]<-paste(tmp[,1],"/1",sep="")
tmp[,1]<-as.Date(tmp[,1])
#change col name
colnames(tmp)[1]<-"date"
#colnames(tmp)[c(2:ncol(tmp))]<-c("")
for(ccc in 2:ncol(tmp)){
cnt<-cnt+1
df.data[[cnt]]<-tmp[,c(1,ccc)]
df.data[[cnt]][,2]<-gsub(" ", "", df.data[[cnt]][,2])
df.data[[cnt]]<-subset(df.data[[cnt]],df.data[[cnt]][,2]!="")
df.data[[cnt]][,2]<-as.double(df.data[[cnt]][,2])
tmp.name<-colnames(df.data[[cnt]])[2]
xts.data[[cnt]]<-as.xts(df.data[[cnt]][,-1],order.by=as.Date(df.data[[cnt]][,1]))
colnames(xts.data[[cnt]])<-tmp.name
yyyy<-as.integer(format(index(xts.data[[cnt]])[1],"%Y"))
mm<-as.integer(format(index(xts.data[[cnt]])[1],"%m"))
ts.data[[cnt]]<-ts(xts.data[[cnt]][,1],start=c(yyyy,mm),frequency=12)
cat(cnt,"\n")
print(colnames(df.data[[cnt]]))
print(class(df.data[[cnt]]))
print(head(df.data[[cnt]],3))
print(tail(df.data[[cnt]],3))
print(class(xts.data[[cnt]]))
print(head(xts.data[[cnt]],3))
print(tail(xts.data[[cnt]],3))
print(class(ts.data[[cnt]]))
print(ts.data[[cnt]])
print(str(ts.data[[cnt]]))
}
}
```

Merge All Time Series Data as xts
-
```{r,message=F,error=F,warning=F}
all.xts.data<-list()
for(ddd in 1:cnt){
if(ddd==1){all.xts.data[[1]]<-xts.data[[ddd]]}else{all.xts.data[[1]]<-merge.xts(all.xts.data[[1]],xts.data[[ddd]])}
}
head(all.xts.data[[1]],3)
tail(all.xts.data[[1]],3)
```

Calculate 1st difference as xts
-
```{r,message=F,error=F,warning=F}
for(ddd in 1:cnt){
if(ddd==1){all.xts.data[[2]]<-diff(na.omit(all.xts.data[[1]][,ddd]))[-1]}else{all.xts.data[[2]]<-merge.xts(all.xts.data[[2]],diff(na.omit(all.xts.data[[1]][,ddd]))[-1])}
}
head(all.xts.data[[2]],3)
tail(all.xts.data[[2]],3)
```

Calculate Logarithmic Return as xts
-
```{r,message=F,error=F,warning=F}
for(ddd in 1:cnt){
if(ddd==1){all.xts.data[[3]]<-diff(log(na.omit(all.xts.data[[1]][,ddd])))[-1]}else{all.xts.data[[3]]<-merge.xts(all.xts.data[[3]],diff(log(na.omit(all.xts.data[[1]][,ddd])))[-1])}
}
head(all.xts.data[[3]],3)
tail(all.xts.data[[3]],3)
```