【问题标题】:(R) How to include arguments when passing a function?(R) 传递函数时如何包含参数?
【发布时间】:2020-12-16 00:09:28
【问题描述】:

对不起,混乱的标​​题。我不确定这个措辞是否正确。

我有以下情况。 SelfLearning()method 参数,它是一个函数。我想要method=LibLinear 并且我想包含LibLinear 本身的参数,即参数type=2。我不知道该怎么做。

如何让 B 之类的东西工作?

library(RSSL)
library(dplyr)
library(ggplot2)

# dummy dataset
df <- generate2ClassGaussian(200, d=2, var = 0.2, expected=TRUE)

# A
# this works, but without LibLinear(type=2)
g_self <- SelfLearning(Class~.,df,
                       method = NearestMeanClassifier,
                       prior=matrix(0.5,2))

# B
# trying to pass method=LibLinear(type=2) does not work
g_self <- SelfLearning(Class~.,df,
                       method = LiblineaR(type=2), # <-- how do I fix this?
                       prior=matrix(0.5,2))

【问题讨论】:

    标签: r function arguments


    【解决方案1】:

    方法的参数可以作为附加参数传递给函数本身。在你的情况下,你可以写:

    g_self <- SelfLearning(Class~.,df,
                           method = LiblineaR,
                           prior=matrix(0.5,2),type=2)
    

    【讨论】:

    • 谢谢。不幸的是,我收到错误“SelfLearning 错误(Class ~ ., df[, 1:2], method = LiblineaR, prior = matrix(0.5, : (list) object cannot be coerced to type 'logical'”,但我认为这是 SelfLearning 和 LiblineaR 的一个更深层次的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多