です。私は、線形回帰の式を作成するための汎用関数を実行しようとしています。私は、関数がデータフレーム内に存在するすべての変数を使用して、ユーザ定義された変数や、 関数のユーザー定義変数が
- を作成することを望みます。
私はデータフレームに存在するすべての変数を使用して数式を作成できますが、ユーザー定義の変数を取得しようとすると問題が発生します。後で変数を使用して後で式。私が今まで持って
機能はこれです:
lmformula <- function (data, IndepVariable = character, VariableList = TRUE){
if (VariableList) {
newlist <- list()
newlist <- # Here is where I do not exactly what to do to extract the variables defined by user
DependVariables <- newlist
f <- as.formula(paste(IndepVariable, "~", paste((DependVariables), collapse = '+')))
}else {
names(data) <- make.names(colnames(data))
DependVariables <- names(data)[!colnames(data)%in% IndepVariable]
f <- as.formula(paste(IndepVariable,"~", paste((DependVariables), collapse = '+')))
return (f)
}
}
任意のヒントが深く理解されるだろうしてください
'f < - as.formula(sprintf("%s〜。 "、dependentVariable))のようなものです。 lm(f、data = data [、Predictors]) 'である。 LHSの回帰では従属変数であり、RHSでは回帰/独立変数であることに注意してください。 – Roland
私の問題は 'DependVariables'です。ユーザーから与えられた変数を取得するにはどうすればよいですか?私が望むのは、ユーザがタイプした変数のリストを 'DependVariables'に保存することです。 – mina