1

今天,我的 R 学习曲线让我变得最好。所以..我有一个多系列动物园对象的列表。我正在尝试将每个中的列重命名为相同的值。我在最后一行尝试这个......它运行没有错误......但名称没有改变。任何想法都会很棒。

require("zoo")

Get monthly data of stocks.
symbs = c('AAPL', 'HOV', 'NVDA')

importData <- lapply(symbs, function(symb) get.hist.quote(instrument= symb, 
      start = "2000-01-01", end = "2013-07-15", quote="AdjClose", provider = "yahoo", 
      origin="1970-01-01", compression = "m", retclass="zoo"))
names(importData) <- symbs

#Calculate monthly pct chgs of stocks.
monthlyPctChgs = lapply(importData, function(x) diff(x, lag = 1) / lag(x, k = -1))
names(monthlyPctChgs) <- symbs

#Merge the pct chgs and the monthly closing prices
pricingAndPerfsMerged = mapply(merge, importData, lag(monthlyPctChgs, k = -1), 
      SIMPLIFY = FALSE)

#Rename the columns in each zoo.
lapply(pricingAndPerfsMerged, function(x) colnames(x) = c('AdjClose', 'MonthlyPerf'))
4

1 回答 1

0

您正在重命名副本的列。这将是一个使用 for 循环的好地方:

for (i in seq_along(pricingAndPerfsMerged)) {
  colnames(pricingAndPerfsMerged[[i]]) = c('AdjClose', 'MonthlyPerf')
}
于 2013-08-13T23:15:12.837 回答