Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maybe you're not getting the plyr or other functions for reshaping the data component. How about something more direct and low level. If you currently just have one line that goes A1, A2, A3... A10, B1-B10, etc. then extract that lump of stuff from your data frame, I'm guessing columns 11-250, and then just make that section the shape you want and put them back together.</p> <pre><code>yDat &lt;- data[, 11:250] yDF &lt;- lapply( 1:nrow(data), function(i) matrix(yDat[i,], ncol = 24) ) yDF &lt;- do.call(rbind, y) #combine the list of matrices returned above into one yDF &lt;- data.frame(yDF) #get it back into a data.frame names(yDF) &lt;- LETTERS[1:24] #might as well name the columns </code></pre> <p>That's the fastest way to get the bulk of your data in the shape you want. All the <code>lapply</code> function did was add dimension attributes to each row so that they were in the shape you wanted and then return them as a list, which was massaged with the subsequent rows. But now it doesn't have any of your ID information from the main data.frame. You just need to replicate each row of the first 10 columns 10 times. Or you can use the convenience function <code>merge</code> to help with that. Make a common column that is already in your first 10 rows one of the columns of the new data.frame and then just merge them.</p> <pre><code>yInfo &lt;- data[, 1:10] ID &lt;- yInfo$ID yDF$ID &lt;- rep( yInfo$ID, each = 10 ) newDat &lt;- merge(yInfo, yDF) </code></pre> <p>And now you're done... mostly, you might want to make an extra column that names the new rows</p> <pre><code>newDat$condNum &lt;- rep(1:10, nrow(newDat)/10) </code></pre> <p>This will be very fast running code. Your data.frame really isn't that big at all and much of the above will execute in a couple of seconds.</p> <p>This is how you should be thinking of data in R. Not that there aren't convenience functions to handle the bulk of this but you should be doing this that avoid looping as much as possible. Technically, what happened above only had one loop, the <code>lapply</code> used right at the start. It had very little in that loop as well (they should be compact when you use them). You're writing in scalar code and it is very very slow in R... even if you weren't really abusing memory and growing data while doing it. Furthermore, keep in mind that, while you can't always avoid a loop of some kind, you can almost always avoid nested loops, which is one of your biggest problems.</p> <p>(read <a href="http://www.burns-stat.com/pages/Tutor/R_inferno.pdf" rel="nofollow">this</a> to better understand your problems in this code... you've made most of the big errors in there)</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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