I'm using the R snippet node in KNIME Labs – R (Interactive) repository. I would need your help to do something easy in principle: using a flow variables content as a variable name.
I explain myself better. I have the following working code:
lm.fit=lm(housecost~.,data=knime.in)
that builds a linear model using the variable “housecost” as response, present in knime.in data. Now I want to generalize the code passing the response variable name (in this case “housecost”) from the outside, inside a flow variable called “response”.
With it I don't get any error. Anyway it seems that the linear model is still not able to take "housecost" as response variable name. Indeed it appears between the other dependent variables.
I attached my workflow. Please, do you have some suggestions?
I have been curious about this for a while now and your question made me finally spend some time looking at it. The best solution I found, was to create the formula for the call to lm manually by constructing the string first and then converting it to a formula. I imagine there is a more elgant way to do it, but I could not discover what this is.
I'm sorry if I come back to this issue but I found that although your solution perfectly work with the R lm() function, it does NOT with the lda() nor the qda() ones (the R functions to calculate Linear Discriminant Analysis and Quadratic Discriminant Analysis, respectively).
It gives me the following error:
Error in lda.default(formula, data = knime.in) : 'x' is not a matrix