r - Creating a Data frame that is populated by a custom function that returns an vector -


I have the following code and what I want to do is to have a dataframe populated, each row should be returned with custom function Rx (It gives vector with number 3).

I have come in two ways to achieve this, but both of them feel somewhat like the work around and I was thinking that there was a better way of suggesting anyone.

Looping through each walk in Method 1 stores the results in the temporary variable and then places it in the correct position in the data frame

In the second method the data is RBIDED , But I have been left with an empty line which should be snatched later.

  n = 500 ff & lt; -c (0.20.3,0.5,0.25) Rx and lieutenant; -function (ff) {# Set Sales Red & Lt; -Runef (3) S & lt; Data frame to maintain (1: 3 in X) for -rep (0,3); Potential prospects from #FF investigation & lt; -cumsum FF / par (FF)) #select first fracture set s [x] & lt; -min (which (probs> = rands [x])) #get Get rid of the set and recycle [x] FF [s] [LC] -0} rx & lt; -s}  

solution

  #th 1 df_sets & lt; -data.frame (s1 = delegate (0, n), s2 (1: n in one) {a & lt; -rx (ff) df_sets $ s1 [i] & lt; -a [1] df_sets $ s2 For = Representative (0, N), S3 = Representative (0, N)) [I] & lt; -a [2] df_sets $ s3 [i] & lt; -a [3]} head (df_sets) # way2 df_sets & lt; For -data.frame (s1 = 0, s2 = 0, s3 = 0) (I 1: n) {a & lt; -rx (ff) df_sets & lt; -rbind (df_sets, a)} df_sets & lt; -df_sets [-1], head (df_sets)  

Edit:

The issue of this function is to create multiple receipts that choose from a predefined vector (Without replacement) which are discrete probabilities. The function RX will use a static input as shown in the above task. To pass a cumulative percentage at each point, it will choose between a random number between 0 and 1 and select a datapoint. Then it will return to this point Chance Function Recalculation and recompare.


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -