I need to use a package that depend on multiple data frames to run (climate, parameters, site conditions and species), I created 4 data frames, each one contains 15 different characteristics of those varibles. I need to run 15 times, so I implemented a loop "for", but didn't work, seem like it keeps using the same climate data.
ps: After I eliminated the colun that contains the subset code, because the package doens't work if I keep it.
The immediate problem is that every iteration overwrites the previous result
successively. You can confirm this by checking that the output data corresponds to what you would expect for N.
The larger problem is conceptual. R can be made to work like other scripting languages, but that's not its strength. Rather, R excels at functional, not procedural, orientation. Every problem in R can be thought of with advantage as an exercise in school algebra, f(x) = y. The three objects, x, y and f (in Reverything is an object) are
x what is at hand y what is desired f converts x to y
In this case x is 4 data frames. For simplicity, I assume they have identical structures.
y is the return value of your package's function on each element of x.
Thus, we can think of f as a composite function f(g(), where g is the package function and f is the function that feeds g.
So, what's an appropriate x? A list is simple.
What function will take a list as an argument and apply g to each. For that, you can look to purrr:map or base::lapply.
Without a reprex, I can't offer a concrete example.
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one: