Skip to content
Prev 309743 / 398503 Next

override date in xts time series

Hi,
Sorry, I forgot to answer the second question.
?txt<-paste("\\10",unique(month(index(x.1))),"\\2",sep="")? #without the as.character() also should work
#because
?str(paste("\\10",unique(month(index(x.1))),"\\2",sep="")) # it returns a character
# chr "\\101\\2"

#Here too:
str(paste(10,unique(month(index(x.1))),2,sep=""))
# chr "1012"
#According to the description in paste()
"Concatenate vectors after converting to character. "


?as.POSIXct(gsub("(.*\\-).*(\\-.*)",txt,index(y.1))) 
#[1] "2004-01-04 01:15:00 EST" "2004-01-04 01:30:00 EST"
#[3] "2004-01-04 01:45:00 EST" "2004-01-04 02:00:00 EST"
#[5] "2004-01-04 02:30:00 EST" "2004-01-04 03:30:00 EST"

#Now, suppose if I want to change both the month and day from the original y.1
?index(y.1)<-as.POSIXct(gsub("(.*\\-).*(\\-).*(\\s.*)","\\101\\207\\3",index(y.1))) #Here, the month will be 01 and day 07
?y.1
#??????????????????? [,1]
#2004-01-07 01:15:00??? 1
#2004-01-07 01:30:00??? 2
#2004-01-07 01:45:00??? 3
#2004-01-07 02:00:00??? 4
#2004-01-07 02:30:00??? 5
#2004-01-07 03:30:00??? 6
Hope it helps.
A.K.