r - How to write function that takes uses the single ouput from another function as starting point for new analysis? -


i am having trouble writing the function calls another function and output to run a new analysis in the loop Uses as a base (or its equivalent). For example, suppose that function 1 creates this output: 10. The second function will take it as the starting point to run the new analysis. The single data point from the second output will be the basis of the next round of analysis, and so on.

Here is a simple example: The question is how to create a loop for this or perhaps a more effective way to use spoiled. In any case, the first task can be as follows:

  f.1 < -function (x) {xa & lt; -seq (x, by = 1, length.out = 5) a.1 & lt; The second function, which calls the first function, can run in the following ways:  
  F.2 & Lt; -function (x) {f.1 & lt; -function (x) {a & lt; -seq (x, by = 1, length.out = 5) a.1 & lt; -ail (a, 1)} z & lt; -f.1 (x) y = z + 1 seq (y, by = 1, length.out = 5)}   

How do I modify f2 () so that it Runs the calculation again which uses the previous output as the basis of the next round of analysis. To be accurate, f.1 (10) output:

[1] 14

In turn, the result in f.2 (10):

[1 ] 15 16 17 18 19 How can I rewrite f.2 () so that it automatically uses f.2 (19) on the next iteration, and do so for many loops continuously. In this process, I want to collect the output in a separate file for review. thanks a lot!

You can try it with two arguments f.2 . . The first argument is x that you need to start with x and n is the number of iterations you want to do. The output of the function will be a matrix with rows and columns of n .

  f.2 & lt; -function (x, n) {c & lt; - For Matrix (Enro = N, NXL = 5) (i in 1: nero (c)) {z   

  f < - f.2 (10, 10) ## with 10 x starting and running of 10 loops [1] [, 2] [, 3] [, 4] [, 5] [1,] 15 16 17 18 19 [ 2,] 24 25 26 27 28 [3,] 33 34 35 36 37 [4], 42 43 44 45 46 [5,] 51 52 53 54 55 [6,] 60 61 62 63 64 [7,] 69 70 71 72 73 [8,] 78 79 80 81 82 [9,] 87 88 89 90 91 [10,] 96 97 98 99 100    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -