0

I have generated nine models using lm() in R, which I've named m1-m9. I'd like to create a prompt whereby the user answers the question:

"Which model would you like to use for further analysis? (m1-m9)"

with the name of the model (m1-m9), simply stated as e.g. "m1". I then want to use the answer given to copy the original model (m1-m9), but rename the copy as "calmod" which will be used for further analysis. I've read several threads dealing with prompts but I'm simply too much of a beginner to get my head around it. Is there any simple way to do this?

Cheers

user09034
  • 15
  • 6
  • Zheyuan Li has answered the original question. However, you should probably never have models `m1` to `m9` but rather a list of 9 models. You can then ask the user for the number of the model in the list and if the user enters something stupid, you do not open up the whole namespace to `get`. Also, if you decide to investigate more than one modell, you can easily loop over a list. Just my two pence. – Bernhard Sep 30 '16 at 11:47
  • 1
    Thanks for the answer and the advice. The lines provided by Zheyuan solved my problem. I will consider adding a list of the models. Very much appreciated. – user09034 Sep 30 '16 at 12:02

1 Answers1

2

Interesting question! We can use

input <- readline("Which model would you like to use for further analysis? (m1-m9): ")
calmod <- get(input)
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248