Note that there are some explanatory texts on larger screens.

plurals
  1. POBootstrap two-way large dataset
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/13104339/bootstrap-a-large-data-set">Bootstrap a large data set</a> </p> </blockquote> <p>I would like to bootstrap a large two-way data set which contains multiple column and row variables. I have to preserve both row and column variables. The result should be a list containing a bootstrap of all column variables for each row variable. I am providing the required code to answer my question but i think it is not elegant. I would appreciate a better and faster code. The following is a simplified re-creation of the two-way data set:</p> <pre><code>rm(list=ls()) data &lt;- 1:72 </code></pre> <p>Create a two way matrix data:</p> <pre><code>charDataDiff &lt;- matrix(data, nrow=9,ncol=8) varNames &lt;- c("A", "B", "C","A", "B", "C","A", "B", "C") </code></pre> <p>Add a character column to the charDataDiff matrix:</p> <pre><code>charDataDiff &lt;- cbind(varNames ,data.frame(charDataDiff)) </code></pre> <p>Add column names:</p> <pre><code>colnames(charDataDiff) &lt;- c("patchId","s380","s390","s400","s410","s420","s430","s440","s450") </code></pre> <p>Separate the data using the row-variable "patchId" as the criteria. This creates three lists: one for each Variable</p> <pre><code>idColor &lt;- c("A", "B", "C") (patchSpectrum &lt;- lapply(idColor, function(idColor) charDataDiff[charDataDiff$patchId==idColor,])) </code></pre> <p>Created the function sampleBoot to sample the patchSpectrum</p> <pre><code>sampleBoot &lt;- function(nbootstrap=2, patch=3){ return(lapply(1:nbootstrap, function(i) {patchSpectrum[[patch]][sample(1:nrow(patchSpectrum[[patch]]),replace=TRUE),]}))} </code></pre> <p>The list "k" answers my question. However, I think my code is slow for a large data set and large bootstrap. I am only bootstrapping 10 iteration for three row variables. A faster more elegant code is appreciated.</p> <pre><code>numBoots &lt;- 10 for (i in 1: numBoots) k &lt;- lapply(1:3, function(n) do.call(rbind, lapply(sampleBoot(i, n), function(x) apply(x[-1], 2, median)))) k </code></pre>
    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.
 

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