gpt4 book ai didi

r - quantmod::chart_Series 和 mapply 给出图表参数错误

转载 作者:行者123 更新时间:2023-12-04 12:56:43 25 4
gpt4 key购买 nike

我如何使用 更多参数正确使用chart_Series?

p.txt

s,n
ABBV,AbbVie
BMY,Bristol
LLY,EliLily
MRK,Merck
PFE,Pfizer

sof.r
# R --silent --vanilla < sof.r
library(quantmod)
options("getSymbols.warning4.0"=FALSE)
options("getSymbols.yahoo.warning"=FALSE)

# setup chart params
cp <- chart_pars()
cp$cex=0.55
cp$mar=c(1,1,0,0) # B,L,T,R
# setup chart theme
ct <- chart_theme()
ct$format.labels <- ' ' # AG: space needed to remove bottom x-axis labels
ct$lylab <- TRUE # AG: enable left y-axis labels
ct$rylab <- FALSE # AG: remove right y-axis labels
ct$grid.ticks.lwd=1

# read values into vectors
csv <- read.csv("p.txt", stringsAsFactors = FALSE)
symVec <- getSymbols(as.vector(csv$s))
infoVec <- mapply(paste, csv$s, csv$n, sep=": ") # eg. SYM: Name
cpVec = rep(cp, times=nrow(csv))

# create PDF
pdf(file = "p.pdf")
par(mfrow = c( 5, 4 ) )
mapply (chart_Series, mget(symVec), name=infoVec, null, null, null, MoreArgs=cp, MoreArgs=ct)
dev.off()

错误
> mapply (chart_Series, mget(symVec), name=infoVec, null, null, null, MoreArgs=cp, MoreArgs=ct)
Error in mapply(chart_Series, mget(symVec), name = infoVec, null, null, :
formal argument "MoreArgs" matched by multiple actual arguments
Execution halted

最佳答案

错误状态 moreArgs由多个参数匹配(您在对 MoreArgs 的调用中提供了两个名为 mapply 的参数),这是您的问题。适用于 chart_Series 每次调用的所有参数必须是 提供给 moreArgs 的命名列表.

您的 MBY符号是有问题的,因为它在 2017 年之后有恒定数据或没有数据,最终在调用 chart_Series 时产生错误。 ,所以为了简单起见,我们放弃这个例子,因为处理它是一个与 mapply 无关的极端情况。 .

这就是你如何使用 mapply在你的例子中:

csv <- data.frame(s = c("ABBV", "MBY", "LLY", "MRK", "PFE"), n = c("AbbVie", "Bristol", "EliLily", "Merck", "Pfizer"))
csv <- csv[-2, ]
symVec <- getSymbols(as.vector(csv$s))
infoVec <- mapply(paste, csv$s, csv$n, sep=": ") # eg. SYM: Name
cpVec = rep(cp, times=nrow(csv))


# Make things a little more interesting in your custom chart theme:
ct$col$up.col<-'darkgreen'
ct$col$dn.col<-'darkred'

par(mfrow = c( 2, 2 ) )
mapply (chart_Series,
# vectorised arguments:
x = mget(symVec), # this is a list of the market data for each symbol, and is consistent with a vectorised argument for `mapply`
name = infoVec, #`simply character vector of the same length as `mget(symVec)`.
# one NAMED list to MoreArgs, with the full names of the arguments in chart_Series you want to complete
MoreArgs = list(pars = cp, theme = ct, subset = "2019"))

关于r - quantmod::chart_Series 和 mapply 给出图表参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57023832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com