Note that there are some explanatory texts on larger screens.

plurals
  1. POVectorize my thinking: Vector Operations in R
    primarykey
    data
    text
    <p>So earlier I answered my own question on thinking in vectors in R. But now I have another problem which I can't 'vectorize.' I know vectors are faster and loops slower, but I can't figure out how to do this in a vector method:</p> <p>I have a data frame (which for sentimental reasons I like to call my.data) which I want to do a full marginal analysis on. I need to remove certain elements one at a time and 'value' the data frame then I need to do the iterating again by removing only the next element. Then do again... and again... The idea is to do a full marginal analysis on a subset of my data. Anyhow, I can't conceive of how to do this in a vector efficient way. </p> <p>I've shortened the looping part of the code down and it looks something like this:</p> <pre><code>for (j in my.data$item[my.data$fixed==0]) { # &lt;-- selects the items I want to loop # through my.data.it &lt;- my.data[my.data$item!= j,] # &lt;-- this kicks item j out of the list sum.data &lt;-aggregate(my.data.it, by=list(year), FUN=sum, na.rm=TRUE) #&lt;-- do an # aggregation do(a.little.dance) &amp;&amp; make(a.little.love) -&gt; get.down(tonight) # &lt;-- a little # song and dance delta &lt;- (get.love) # &lt;-- get some love delta.list&lt;-append(delta.list, delta, after=length(delta.list)) #&lt;-- put my love # in a vector } </code></pre> <p>So obviously I hacked out a bunch of stuff in the middle, just to make it less clumsy. The goal would be to remove the j loop using something more vector efficient. Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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