Note that there are some explanatory texts on larger screens.

plurals
  1. POAppend rle result from loop
    text
    copied!<p>I am running a coin-toss simulation with a loop which runs about 1 million times.</p> <p>Each time I run the loop I wish to retain the table output from the RLE command. Unfortunately a simple append does not seem to be appropriate. Each time I run the loop I get a slightly different amount of data which seems to be one of the sticking points.</p> <p>This code gives an idea of what I am doing:</p> <pre><code>N &lt;- 5 #Number of times to run rlex &lt;-NULL #begin loop############################# for (i in 1:N) { #tells R to repeat N number x &lt;-sample(0:1, 100000, 1/2) rlex &lt;-append(rlex, rle(x)) } table(rlex) #doesn't work table(rle(x)) #only 1 </code></pre> <p>So instead of having five separate rle results (in this simulation, 1 million in the full version), I want one merged rle table. Hope this is clear. Obviously my actual code is a bit more complex, hence any solution should be as close to what I have specified as possible.</p> <p>UPDATE: The loop is an absolute requirement. No ifs or buts. Perhaps I can pull out the table(rle(x)) data and put it into a matrix. However again the stumbling block is the fact that some of the less frequent run lengths do not always turn up in each loop. Thus I guess I am looking to conditionally fill a matrix based on the run length number?</p> <p>Last update before I give up: Retaining the rle$values will mean that too much data is being retained. My simulation is large-scale and I really only wish to retain the table output of the rle. Either I retain each table(rle(x)) for each loop and combine by hand (there will be thousands), or I find a programmatic way to keep the data (yes for zeroes and ones) and have one table that is formed from merging each of the individual loops as I go along. </p> <p>Either this is easyish to do, as specified, or I will not be doing it. It may seem a silly idea/request, but that should be incidental to whether it can be done. </p> <p><strong>Seriously last time</strong>. Here is an animated gif showing what I expect to happen. <img src="https://i.stack.imgur.com/GRMDx.gif" alt="enter image description here"></p> <p>After each iteration of the loop data is added to the table. This is as clear as I am going to be able to communicate it.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload