ここに1つの方法は、
library(quantmod)
getSymbols("SPY", src='yahoo', from='2000-01-01', to='2012-01-01')
SPY <- as.zoo(Ad(SPY))
# Now I have zoo data with a single value for each day (like you say you have)
# Convert it to xts so that I can use xts' split method
mydata <- as.xts(SPY)
# Split data by years. Give them rownames that are day of year instead of
# specific dates. cbind data together and plot
ts.plot(do.call(cbind, lapply(split(mydata, 'years'), function(x) {
zoo(x, 1:NROW(x))
})), col=rainbow(nyears(mydata)))
また、
tapply(SPY, format(index(SPY), "%Y"), c)
は年によって分割されますだとxts
に変換する必要はありません。お返事ありがとうございました。実際には、これらは日付ですが(YYYY-mm-ddの形式)、年の日はありません。 – tagoma
とにかく、あなたが提案したコードをちょっと変えましたが、それはうまくいきますが、私は水平軸上で月の方が(約)250ではなく、整数ではなく月を好むこと以外はうまくいきます。 – tagoma
水平軸を1年の長さですか?その場合は、インデックスを変更する必要があります。インデックスを変更しないと、1年以上の横軸があります。 – GSee