我有一个xts
个对象的列表。对象是月度时间序列,我想将它们汇总到每季度。使用to.quarterly
或apply.quarterly
通过lapply
失败:
l.qtr <- lapply(l.adj, function(x) apply.quarterly(x, mean))
结果:
Error in try.xts(x, error = "must be either xts-coercible or timeBased") :
must be either xts-coercible or timeBased
但是我可以使用另一个xts
对象列表来调用lx
。此lx
列表将被发送,转换为ts
个对象,X12已调整并重新标记为xts
并已发回。不知怎的,当它回来时我得到了错误。我已经验证了对于大小为1的列表不存在的问题,即使在将其发送到X12调整后也是如此。
认为这是一个问题,就像在这个链接,但似乎不是? Automatically plot (and save) list of xts objects
还有什么好帮手?这让我疯了。
更新
对最初缺乏重点表示歉意。我一直试图将其缩小到一个严格的可重复的例子。它似乎是我的帮助函数SeasAdj
(转换为ts
,延迟转换并转换回xts
)和我的data.frame
初始转换为xts
。但是,如果我运行通过xts
quantmod's
下载的getSymbols
月度系列,我会得到所需的结果。这让我相信麻烦在于SeasAdj辅助函数在返回之前如何转换回xts
。我最后有dput(lax)
。在采购SeasAdj后,从那里运行这四条线:
lax.xts <- xts(lax$value, order.by=lax$date)
lax.adj <- SeasAdj(lax.xts)
lax.qtr <- apply.quarterly(lax.adj, mean)
lax.q <- apply.quarterly(lax.xts, mean)
SeasAdj <- function(x) {
require(x12)
require(quantmod)
freq <- switch(periodicity(x)$scale,
daily=365,
weekly=52,
monthly=12,
quarterly=4,
yearly=1)
## determine the start date from xts
pltStart <- as.POSIXlt(start(x))
# create 2 arg vector with year, month for start
Start <- c(pltStart$year+1900,pltStart$mon+1)
# capture xts series name
names <- dimnames(x)
#pass info as args to create ts
x.ts <- ts(x, start=Start, frequency=freq)
## use x12 automodel
# do some seasonal adjustment using x12
# return a TS object with data and seasonally adjusted data
x12out <- x12work(x.ts,
x12path="C:\\x12arima\\x12a.exe",
transform.function="auto",
automdl=TRUE)
# assign adjusted and original series to vectors
x.adj <- as.ts(x12out$d11)
x.orig <- as.ts(x12out$a1)
# convert to XTS
xts.adj <- as.xts(x.adj)
# assign dimname back to series
dimnames(xts.adj) <- names
# return XTS object
return(xts.adj)
}
这是一个松懈的命运 dput(不严)
structure(list(series_id = c("LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003",
"LAUCN55063003", "LAUCN55063003", "LAUCN55063003", "LAUCN55063003"
), year = c(1990L, 1990L, 1990L, 1990L, 1990L, 1990L, 1990L,
1990L, 1990L, 1990L, 1990L, 1990L, 1991L, 1991L, 1991L, 1991L,
1991L, 1991L, 1991L, 1991L, 1991L, 1991L, 1991L, 1991L, 1992L,
1992L, 1992L, 1992L, 1992L, 1992L, 1992L, 1992L, 1992L, 1992L,
1992L, 1992L, 1993L, 1993L, 1993L, 1993L, 1993L, 1993L, 1993L,
1993L, 1993L, 1993L, 1993L, 1993L, 1994L, 1994L, 1994L, 1994L,
1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1994L, 1995L,
1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L, 1995L,
1995L, 1995L, 1996L, 1996L, 1996L, 1996L, 1996L, 1996L, 1996L,
1996L, 1996L, 1996L, 1996L, 1996L, 1997L, 1997L, 1997L, 1997L,
1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1997L, 1998L,
1998L, 1998L, 1998L, 1998L, 1998L, 1998L, 1998L, 1998L, 1998L,
1998L, 1998L, 1999L, 1999L, 1999L, 1999L, 1999L, 1999L, 1999L,
1999L, 1999L, 1999L, 1999L, 1999L, 2000L, 2000L, 2000L, 2000L,
2000L, 2000L, 2000L, 2000L, 2000L, 2000L, 2000L, 2000L, 2001L,
2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L, 2001L,
2001L, 2001L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L,
2002L, 2002L, 2002L, 2002L, 2002L, 2003L, 2003L, 2003L, 2003L,
2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2003L, 2004L,
2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L, 2004L,
2004L, 2004L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L, 2005L,
2005L, 2005L, 2005L, 2005L, 2005L, 2006L, 2006L, 2006L, 2006L,
2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2006L, 2007L,
2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L, 2007L,
2007L, 2007L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L, 2008L,
2008L, 2008L, 2008L, 2008L, 2008L, 2009L, 2009L, 2009L, 2009L,
2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2009L, 2010L,
2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L,
2010L, 2010L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L,
2011L, 2011L, 2011L, 2011L, 2011L, 2012L, 2012L, 2012L, 2012L,
2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2012L, 2013L,
2013L, 2013L, 2013L, 2013L, 2013L), period = c("01", "02", "03",
"04", "05", "06", "07", "08", "09", "10", "11", "12", "01", "02",
"03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "01",
"02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
"12", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
"11", "12", "01", "02", "03", "04", "05", "06", "07", "08", "09",
"10", "11", "12", "01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12", "01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12", "01", "02", "03", "04", "05",
"06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04",
"05", "06", "07", "08", "09", "10", "11", "12", "01", "02", "03",
"04", "05", "06", "07", "08", "09", "10", "11", "12", "01", "02",
"03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "01",
"02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
"12", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
"11", "12", "01", "02", "03", "04", "05", "06", "07", "08", "09",
"10", "11", "12", "01", "02", "03", "04", "05", "06", "07", "08",
"09", "10", "11", "12", "01", "02", "03", "04", "05", "06", "07",
"08", "09", "10", "11", "12", "01", "02", "03", "04", "05", "06",
"07", "08", "09", "10", "11", "12", "01", "02", "03", "04", "05",
"06", "07", "08", "09", "10", "11", "12", "01", "02", "03", "04",
"05", "06", "07", "08", "09", "10", "11", "12", "01", "02", "03",
"04", "05", "06", "07", "08", "09", "10", "11", "12", "01", "02",
"03", "04", "05", "06"), value = c(4.7, 5, 4.8, 3.6, 3.4, 3.5,
4, 3.4, 3.1, 3.1, 4, 4.1, 4.7, 5.2, 5.2, 4.1, 3.7, 4.5, 4.3,
3.6, 3.3, 3.5, 3.9, 4.2, 4.7, 5.3, 5, 4.1, 4.5, 5.2, 4.7, 4.3,
4, 3.6, 3.8, 3.9, 4.7, 5.2, 4.6, 3.9, 3.8, 4.4, 4.7, 4, 3.8,
3.6, 3.5, 3.8, 4.9, 5.1, 4.8, 3.9, 3.4, 3.9, 4.2, 3.5, 3, 2.6,
2.7, 2.8, 4.3, 4.7, 4.5, 4.2, 3.5, 4.1, 3.8, 3.5, 3, 2.9, 3.2,
3.2, 4.1, 4.5, 4.3, 3.2, 2.9, 3, 2.8, 2.6, 2.2, 2.1, 2.5, 2.6,
3.7, 3.6, 3.9, 3.1, 2.5, 2.8, 2.6, 2.5, 2.2, 2.1, 2.4, 2.4, 3.3,
3.3, 3.6, 2.3, 2.3, 3, 2.3, 2.6, 2.4, 2.4, 2.4, 2.5, 3.3, 3.7,
3.1, 2.6, 2.5, 3.1, 2.5, 3.2, 2.8, 2.7, 2.7, 3, 3.7, 3.9, 3.9,
3, 2.8, 3.5, 3.1, 3.1, 2.6, 2.5, 2.8, 2.9, 3.8, 4.1, 4.5, 3.7,
3.4, 3.9, 3.5, 3.6, 3.3, 3.2, 3.6, 3.8, 4.8, 5, 5.2, 4.7, 4.1,
4.6, 4.2, 4.2, 3.6, 3.5, 4, 4, 5.2, 5.6, 5.3, 4.6, 4.3, 5, 4.5,
4.4, 3.9, 3.8, 4, 3.9, 5.1, 5.1, 5.5, 4, 3.8, 4.4, 3.8, 3.8,
3.5, 3.3, 3.6, 3.5, 4.7, 5.1, 4.9, 3.8, 3.8, 4.3, 3.9, 3.8, 3.7,
3.3, 3.7, 3.8, 4.3, 4.5, 4.4, 3.8, 3.4, 4, 3.7, 3.6, 3.3, 3.1,
3.4, 3.6, 4.6, 4.5, 4.3, 3.8, 3.6, 4.2, 3.8, 3.6, 3.4, 3.3, 3.3,
3.6, 4, 4, 3.9, 3.2, 3.3, 4.2, 3.9, 3.9, 3.6, 3.7, 4.1, 4.8,
6.2, 7, 7.5, 6.7, 6.7, 7.6, 7, 6.9, 6.5, 6.3, 6.3, 6.7, 7.8,
7.7, 7.7, 6.3, 6.1, 6.4, 6.5, 6.2, 5.6, 5.4, 5.5, 5.4, 6.4, 6.6,
6.3, 5.6, 5.5, 6.6, 6.1, 5.9, 5.3, 5.1, 5, 5, 5.9, 6.2, 5.8,
4.9, 5.1, 6, 5.8, 5.5, 4.7, 4.6, 4.7, 4.9, 6.3, 6.3, 5.7, 5.3,
5.1, 5.7), footnote_codes = c("", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
"S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",
"S", "S", "S", "S", "S", "S", "S", "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, 11L, 0L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 0L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 0L, 1L, 2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 10L, 11L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 11L, 0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L,
0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 0L, 1L,
2L, 3L, 4L, 5L), year = c(90L, 90L, 90L, 90L, 90L, 90L, 90L,
90L, 90L, 90L, 90L, 90L, 91L, 91L, 91L, 91L, 91L, 91L, 91L,
91L, 91L, 91L, 91L, 91L, 92L, 92L, 92L, 92L, 92L, 92L, 92L,
92L, 92L, 92L, 92L, 92L, 93L, 93L, 93L, 93L, 93L, 93L, 93L,
93L, 93L, 93L, 93L, 93L, 94L, 94L, 94L, 94L, 94L, 94L, 94L,
94L, 94L, 94L, 94L, 94L, 95L, 95L, 95L, 95L, 95L, 95L, 95L,
95L, 95L, 95L, 95L, 95L, 96L, 96L, 96L, 96L, 96L, 96L, 96L,
96L, 96L, 96L, 96L, 96L, 97L, 97L, 97L, 97L, 97L, 97L, 97L,
97L, 97L, 97L, 97L, 97L, 98L, 98L, 98L, 98L, 98L, 98L, 98L,
98L, 98L, 98L, 98L, 98L, 99L, 99L, 99L, 99L, 99L, 99L, 99L,
99L, 99L, 99L, 99L, 99L, 100L, 100L, 100L, 100L, 100L, 100L,
100L, 100L, 100L, 100L, 100L, 100L, 101L, 101L, 101L, 101L,
101L, 101L, 101L, 101L, 101L, 101L, 101L, 101L, 102L, 102L,
102L, 102L, 102L, 102L, 102L, 102L, 102L, 102L, 102L, 102L,
103L, 103L, 103L, 103L, 103L, 103L, 103L, 103L, 103L, 103L,
103L, 103L, 104L, 104L, 104L, 104L, 104L, 104L, 104L, 104L,
104L, 104L, 104L, 104L, 105L, 105L, 105L, 105L, 105L, 105L,
105L, 105L, 105L, 105L, 105L, 105L, 106L, 106L, 106L, 106L,
106L, 106L, 106L, 106L, 106L, 106L, 106L, 106L, 107L, 107L,
107L, 107L, 107L, 107L, 107L, 107L, 107L, 107L, 107L, 107L,
108L, 108L, 108L, 108L, 108L, 108L, 108L, 108L, 108L, 108L,
108L, 108L, 109L, 109L, 109L, 109L, 109L, 109L, 109L, 109L,
109L, 109L, 109L, 109L, 110L, 110L, 110L, 110L, 110L, 110L,
110L, 110L, 110L, 110L, 110L, 110L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 112L, 112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L,
113L, 113L, 113L, 113L, 113L, 113L), wday = c(1L, 4L, 4L,
0L, 2L, 5L, 0L, 3L, 6L, 1L, 4L, 6L, 2L, 5L, 5L, 1L, 3L, 6L,
1L, 4L, 0L, 2L, 5L, 0L, 3L, 6L, 0L, 3L, 5L, 1L, 3L, 6L, 2L,
4L, 0L, 2L, 5L, 1L, 1L, 4L, 6L, 2L, 4L, 0L, 3L, 5L, 1L, 3L,
6L, 2L, 2L, 5L, 0L, 3L, 5L, 1L, 4L, 6L, 2L, 4L, 0L, 3L, 3L,
6L, 1L, 4L, 6L, 2L, 5L, 0L, 3L, 5L, 1L, 4L, 5L, 1L, 3L, 6L,
1L, 4L, 0L, 2L, 5L, 0L, 3L, 6L, 6L, 2L, 4L, 0L, 2L, 5L, 1L,
3L, 6L, 1L, 4L, 0L, 0L, 3L, 5L, 1L, 3L, 6L, 2L, 4L, 0L, 2L,
5L, 1L, 1L, 4L, 6L, 2L, 4L, 0L, 3L, 5L, 1L, 3L, 6L, 2L, 3L,
6L, 1L, 4L, 6L, 2L, 5L, 0L, 3L, 5L, 1L, 4L, 4L, 0L, 2L, 5L,
0L, 3L, 6L, 1L, 4L, 6L, 2L, 5L, 5L, 1L, 3L, 6L, 1L, 4L, 0L,
2L, 5L, 0L, 3L, 6L, 6L, 2L, 4L, 0L, 2L, 5L, 1L, 3L, 6L, 1L,
4L, 0L, 1L, 4L, 6L, 2L, 4L, 0L, 3L, 5L, 1L, 3L, 6L, 2L, 2L,
5L, 0L, 3L, 5L, 1L, 4L, 6L, 2L, 4L, 0L, 3L, 3L, 6L, 1L, 4L,
6L, 2L, 5L, 0L, 3L, 5L, 1L, 4L, 4L, 0L, 2L, 5L, 0L, 3L, 6L,
1L, 4L, 6L, 2L, 5L, 6L, 2L, 4L, 0L, 2L, 5L, 1L, 3L, 6L, 1L,
4L, 0L, 0L, 3L, 5L, 1L, 3L, 6L, 2L, 4L, 0L, 2L, 5L, 1L, 1L,
4L, 6L, 2L, 4L, 0L, 3L, 5L, 1L, 3L, 6L, 2L, 2L, 5L, 0L, 3L,
5L, 1L, 4L, 6L, 2L, 4L, 0L, 3L, 4L, 0L, 2L, 5L, 0L, 3L, 6L,
1L, 4L, 6L, 2L, 5L, 5L, 1L, 3L, 6L), yday = c(0L, 31L, 59L,
90L, 120L, 151L, 181L, 212L, 243L, 273L, 304L, 334L, 0L,
31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L, 273L, 304L,
334L, 0L, 31L, 60L, 91L, 121L, 152L, 182L, 213L, 244L, 274L,
305L, 335L, 0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L,
273L, 304L, 334L, 0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L,
243L, 273L, 304L, 334L, 0L, 31L, 59L, 90L, 120L, 151L, 181L,
212L, 243L, 273L, 304L, 334L, 0L, 31L, 60L, 91L, 121L, 152L,
182L, 213L, 244L, 274L, 305L, 335L, 0L, 31L, 59L, 90L, 120L,
151L, 181L, 212L, 243L, 273L, 304L, 334L, 0L, 31L, 59L, 90L,
120L, 151L, 181L, 212L, 243L, 273L, 304L, 334L, 0L, 31L,
59L, 90L, 120L, 151L, 181L, 212L, 243L, 273L, 304L, 334L,
0L, 31L, 60L, 91L, 121L, 152L, 182L, 213L, 244L, 274L, 305L,
335L, 0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L, 273L,
304L, 334L, 0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L,
273L, 304L, 334L, 0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L,
243L, 273L, 304L, 334L, 0L, 31L, 60L, 91L, 121L, 152L, 182L,
213L, 244L, 274L, 305L, 335L, 0L, 31L, 59L, 90L, 120L, 151L,
181L, 212L, 243L, 273L, 304L, 334L, 0L, 31L, 59L, 90L, 120L,
151L, 181L, 212L, 243L, 273L, 304L, 334L, 0L, 31L, 59L, 90L,
120L, 151L, 181L, 212L, 243L, 273L, 304L, 334L, 0L, 31L,
60L, 91L, 121L, 152L, 182L, 213L, 244L, 274L, 305L, 335L,
0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L, 273L, 304L,
334L, 0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L, 273L,
304L, 334L, 0L, 31L, 59L, 90L, 120L, 151L, 181L, 212L, 243L,
273L, 304L, 334L, 0L, 31L, 60L, 91L, 121L, 152L, 182L, 213L,
244L, 274L, 305L, 335L, 0L, 31L, 59L, 90L, 120L, 151L), isdst = c(0L,
0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L,
1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L,
1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L,
1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L,
0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L)), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXlt", "POSIXt"))), .Names = c("series_id",
"year", "period", "value", "footnote_codes", "date"), row.names = c(40841L,
40842L, 40843L, 40844L, 40845L, 40846L, 40847L, 40848L, 40849L,
40850L, 40851L, 40852L, 40854L, 40855L, 40856L, 40857L, 40858L,
40859L, 40860L, 40861L, 40862L, 40863L, 40864L, 40865L, 40867L,
40868L, 40869L, 40870L, 40871L, 40872L, 40873L, 40874L, 40875L,
40876L, 40877L, 40878L, 40880L, 40881L, 40882L, 40883L, 40884L,
40885L, 40886L, 40887L, 40888L, 40889L, 40890L, 40891L, 40893L,
40894L, 40895L, 40896L, 40897L, 40898L, 40899L, 40900L, 40901L,
40902L, 40903L, 40904L, 40906L, 40907L, 40908L, 40909L, 40910L,
40911L, 40912L, 40913L, 40914L, 40915L, 40916L, 40917L, 40919L,
40920L, 40921L, 40922L, 40923L, 40924L, 40925L, 40926L, 40927L,
40928L, 40929L, 40930L, 40932L, 40933L, 40934L, 40935L, 40936L,
40937L, 40938L, 40939L, 40940L, 40941L, 40942L, 40943L, 40945L,
40946L, 40947L, 40948L, 40949L, 40950L, 40951L, 40952L, 40953L,
40954L, 40955L, 40956L, 40958L, 40959L, 40960L, 40961L, 40962L,
40963L, 40964L, 40965L, 40966L, 40967L, 40968L, 40969L, 40971L,
40972L, 40973L, 40974L, 40975L, 40976L, 40977L, 40978L, 40979L,
40980L, 40981L, 40982L, 40984L, 40985L, 40986L, 40987L, 40988L,
40989L, 40990L, 40991L, 40992L, 40993L, 40994L, 40995L, 40997L,
40998L, 40999L, 41000L, 41001L, 41002L, 41003L, 41004L, 41005L,
41006L, 41007L, 41008L, 41010L, 41011L, 41012L, 41013L, 41014L,
41015L, 41016L, 41017L, 41018L, 41019L, 41020L, 41021L, 41023L,
41024L, 41025L, 41026L, 41027L, 41028L, 41029L, 41030L, 41031L,
41032L, 41033L, 41034L, 41036L, 41037L, 41038L, 41039L, 41040L,
41041L, 41042L, 41043L, 41044L, 41045L, 41046L, 41047L, 41049L,
41050L, 41051L, 41052L, 41053L, 41054L, 41055L, 41056L, 41057L,
41058L, 41059L, 41060L, 41062L, 41063L, 41064L, 41065L, 41066L,
41067L, 41068L, 41069L, 41070L, 41071L, 41072L, 41073L, 41075L,
41076L, 41077L, 41078L, 41079L, 41080L, 41081L, 41082L, 41083L,
41084L, 41085L, 41086L, 41088L, 41089L, 41090L, 41091L, 41092L,
41093L, 41094L, 41095L, 41096L, 41097L, 41098L, 41099L, 41101L,
41102L, 41103L, 41104L, 41105L, 41106L, 41107L, 41108L, 41109L,
41110L, 41111L, 41112L, 41114L, 41115L, 41116L, 41117L, 41118L,
41119L, 41120L, 41121L, 41122L, 41123L, 41124L, 41125L, 41127L,
41128L, 41129L, 41130L, 41131L, 41132L, 41133L, 41134L, 41135L,
41136L, 41137L, 41138L, 41140L, 41141L, 41142L, 41143L, 41144L,
41145L), class = "data.frame")
答案 0 :(得分:1)
为我工作
library(quantmod)
e <- new.env()
s <- c("SPY", "DIA", "GLD")
getSymbols(s, env=e)
l.adj <- eapply(e, Ad)[s]
l.qtr <- lapply(l.adj, function(x) apply.quarterly(x, mean))
修改
代码仍然不可重复(或最小),但dimnames(xts.adj) <- names
看起来很可疑。看起来您将dimnames设置为NULL(请参阅lapply(split(lax.xts, "quarters"), dimnames)
)
如果将xts的dimnames设置为NULL,则最终会将其变为as.xts
无法转换为xts
的内容。我认为这可能不是xts:::`dimnames<-.xts`
的预期行为。
由于我无法运行您的代码,我不确定这是否是问题,但如果是,则这是一个更简洁,可重现的示例。
x <- xts(1:5, .POSIXct(0)+1:5)
dimnames(x) <- dimnames(x)
as.xts(x)
#Error in as.xts.matrix(x) :
# order.by must be either 'rownames()' or otherwise specified