Loop entire script -- more than one R variable

Asked

Viewed 58 times

1

I have a script with five variables.

Suppose the variables and their data types/classes are the following:

  • var1(date)
  • var2(date)
  • var3(date)
  • var4(date)
  • var5(Numeric)

I would like to import a spreadsheet with each column/ input corresponding to the name and type of variables in a dataframe. So:

df <- xlsx("planilha.xlsx", sheet = "nome_plan")

It would be possible to iterate the entire code for each of the dataframe lines?

Something like:

for (i in df) {
    executar_script(i)
}
  • 1

    Fernando, anything is possible, but it would be easier to suggest if we know what you have and what you want. Describe your problem better.

  • Follow the whole script: https://pastebin.com/dEt9EMhz. The five variables are commented at the beginning.

  • 1

    I have my doubts whether the people here will want to read and understand a script with 376 lines that they did not write. Try to reduce your question to something simpler and reproducible. Preferably by giving a.

  • 2

    Reinforcing the previous comment, no one will stop to understand a 300+ line sript just to answer a question about loop; write a simple test script and post it along with an example of data. But what you can do in your case is write your script as a function, saving it in a separate file. Click with source and use family functions apply to apply it to the various elements of a list or date..

  • Carlos, I’ll do it. Thank you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.