gpt4 book ai didi

r - 函数错误: argument 3 matches multiple formal arguments

转载 作者:行者123 更新时间:2023-12-02 09:44:44 28 4
gpt4 key购买 nike

这段代码:

f1 <- function(abc , ac , df){
list(f1 = abc , f2=ac , f3 = df)
}

f1(1,2,a=3)

返回错误:

Error in f1(1, 2, a = 3) : argument 3 matches multiple formal arguments

此错误的原因是 a 与函数 f1 中的参数 abcac 相匹配,因为函数部分匹配

最佳答案

当命名参数与任何形式参数不完全匹配时,R 尝试按前缀应用部分匹配。abcac 都以“a”开头,R 不知道应该使用哪一个,所以它会引发错误。

如果您使用f1(1, 2, ac=3),那么 R 会将 3 分配给 ac,然后它将剩余的值分配给剩余的未分配的参数,因此,1abc2df

关于r - 函数错误: argument 3 matches multiple formal arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47606805/

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