Hi,
dat1<- read.csv("me.csv",header=TRUE,stringsAsFactors=FALSE)
dat1$y<- as.Date(dat1$y,format="%d/%m/%Y")
library(zoo)
z1<- zoo(dat1[,-1],dat1[,1])
library(xts)
library(lubridate)
lst1<-lapply(split(z1,month(index(z1))),as.xts)
head(lst1[[1]])
# [,1]
#1961-01-01 7.45
#1962-01-01 17.63
#1963-01-01 52.23
#1964-01-01 26.92
#1965-01-01 22.11
#1966-01-01 67.43
tail(lst1[[12]])
# [,1]
#2000-12-01 17.90
#2001-12-01 8.69
#2002-12-01 8.21
#2003-12-01 5.94
#2004-12-01 39.94
#2005-12-01 10.35
#or
you can convert to data.frame
datNew<-do.call(rbind,lapply(lst1,as.data.frame))
row.names(datNew)<-gsub("^.*\\.","",row.names(datNew))
head(datNew)
# V1
#1961-01-01 7.45
#1962-01-01 17.63
#1963-01-01 52.23
#1964-01-01 26.92
#1965-01-01 22.11
#1966-01-01 67.43
head(dat1)
# y x
#1 1961-01-01 7.45
#2 1961-02-01 7.92
#3 1961-03-01 7.34
#4 1961-04-01 15.08
#5 1961-05-01 25.66
#6 1961-06-01 26.78
#or
x1<- as.xts(z1)
datNew2<-data.frame(x=coredata(x1)[order(month(index(x1)))])
rownames(datNew2)<-index(x1)[order(month(index(x1)))]
colnames(datNew)<-"x"
identical(datNew,datNew2)
#[1] TRUE
A.K.
________________________________
From: Zilefac Elvis <
zilefa...@yahoo.com>
To: arun <
smartp...@yahoo.com>
Cc: R help <
r-h...@r-project.org>
Sent: Thursday, May 23, 2013 12:32 AM