I am new to R, and I am not really sure how to phrase the title of the question. I am trying to make a script that I can use on different dataframes, only changing the name of the testing variable. For instance, if I have one dataframe (df) with training data train.data with X Y Z variables and I want to test on X, i.e.
testSVM.model<-svm(df$X ~ ., data =train.data)
Then I have another set of data that I want to use the same script on but the dataframe has the structure I J K L and I want to test on J, i.e.
testSVM.model<-svm(df$J ~ ., data =train.data)
instead of writing 2 different scripts, I would like to assign the variable of interest to a variable such as variable.test, which would just need assignment before running the script.
I have tried setting this variable to a constant
variable.test<-'X'
and use
testSVM.model<-svm(df$'variable.test' ~ ., data =train.data)
but this gives an error, so not correct.
I have also tried, but know this is incorrect, to set the variable to the df data
variable.test<-df$X
and use
testSVM.model<-svm(variable.test ~ ., data =train.data)
Again, I am not sure how to properly phrase the question for the header, and I have done about 2 hours of SO searching and Google, but to no avail.