(R) 如何在传递函数时包含参数?
(R) How to include arguments when passing a function?
抱歉标题乱七八糟。我不确定对此的正确措辞。
我有以下情况。 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))
方法的参数可以作为附加参数传递给函数本身。在你的情况下,你可以写:
g_self <- SelfLearning(Class~.,df,
method = LiblineaR,
prior=matrix(0.5,2),type=2)
抱歉标题乱七八糟。我不确定对此的正确措辞。
我有以下情况。 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))
方法的参数可以作为附加参数传递给函数本身。在你的情况下,你可以写:
g_self <- SelfLearning(Class~.,df,
method = LiblineaR,
prior=matrix(0.5,2),type=2)