時系列データからNAの日付を削除

> dataset1<-read.table(file="sample1.csv",header=TRUE,sep=",")

> head(dataset1)
      date usdjpy
1 2013/1/1     NA
2 2013/1/2     NA
3 2013/1/3     NA
4 2013/1/4  87.72
5 2013/1/5     NA
6 2013/1/6     NA

> dataset1[,1]<-as.Date(dataset1[,1])

> head(dataset1)
        date usdjpy
1 2013-01-01     NA
2 2013-01-02     NA
3 2013-01-03     NA
4 2013-01-04  87.72
5 2013-01-05     NA
6 2013-01-06     NA

> dataset2<-subset(dataset1,is.na(dataset1[,2])==FALSE)

> head(dataset2)
         date usdjpy
4  2013-01-04  87.72
7  2013-01-07  88.22
8  2013-01-08  87.27
9  2013-01-09  86.91
10 2013-01-10  88.14
11 2013-01-11  89.34

> write.table(dataset2,file="sample.csv",sep=",",quote=FALSE,row.names=FALSE)

> png(file="sample.png")

> plot(dataset2[,1],dataset2[,2],type="o")

> dev.off()
windows 
      2 
>  

sample