データフレームからxtsおよびxtsからデータフレーム

> #data.frame to xts
> print(head(dataset,5))
        date VALUE
1 1968-04-01  38.0
2 1968-04-02  37.6
3 1968-04-03  37.7
4 1968-04-04  36.7
5 1968-04-05  37.2

> #pattern1
> dataset.xts<-as.xts(dataset[,-1],order.by=as.Date(dataset$date))

> print(head(dataset.xts,5))
           [,1]
1968-04-01 38.0
1968-04-02 37.6
1968-04-03 37.7
1968-04-04 36.7
1968-04-05 37.2

> #pattern2
> dataset.xts<-as.xts(read.zoo(dataset))

> print(head(dataset.xts,5))
           [,1]
1968-04-01 38.0
1968-04-02 37.6
1968-04-03 37.7
1968-04-04 36.7
1968-04-05 37.2

> #colname
> colnames(dataset.xts)<-colnames(dataset)[ c(2:ncol(dataset)) ]

> print(head(dataset.xts,5))
           VALUE
1968-04-01  38.0
1968-04-02  37.6
1968-04-03  37.7
1968-04-04  36.7
1968-04-05  37.2

> #xts to data.frame
> dataset<-data.frame(date=index(dataset.xts),dataset.xts, row.names=NULL)

> print(head(dataset,5))
        date VALUE
1 1968-04-01  38.0
2 1968-04-02  37.6
3 1968-04-03  37.7
4 1968-04-04  36.7
5 1968-04-05  37.2
> 
#path
username<-Sys.info()['user']
path01<-paste("C:/Users/",username,"/Desktop/R_Data_Read/",sep="")
path02<-paste("C:/Users/",username,"/Desktop/R_Graph/",sep="")
path03<-paste("C:/Users/",username,"/Desktop/R_Data_Write/",sep="")
setwd(path01)
#package
library(xts)
#analytics
for(iii in 1:length(dir(path01))){
dataset<-read.table(file=dir(path01)[iii],header=TRUE,sep=",")
dataset[,1]<-as.Date(dataset[,1])
colnames(dataset)[1]<-"date" #小文字
for(ccc in 2:ncol(dataset)){
dataset<-subset(dataset,dataset[,ccc]!=".")
dataset<-subset(dataset,is.na(dataset[,ccc])==F)
dataset[,ccc]<-as.double(as.character(dataset[,ccc]))
}
}
#data.frame to xts
print(head(dataset,5))
#pattern1
dataset.xts<-as.xts(dataset[,-1],order.by=as.Date(dataset$date))
print(head(dataset.xts,5))
#pattern2
dataset.xts<-as.xts(read.zoo(dataset))
print(head(dataset.xts,5))
#colname
colnames(dataset.xts)<-colnames(dataset)[ c(2:ncol(dataset)) ]
print(head(dataset.xts,5))
#xts to data.frame
dataset<-data.frame(date=index(dataset.xts),dataset.xts, row.names=NULL)
print(head(dataset,5))