title: save different objects resulting from a for loop
body: <p>I am trying to save different objects resulting from a for loop.</p>
  
  <p>This is my matrix and subsetting that I needed:</p>
  
  <pre><code>row.names &lt;- c('A2003','B2010','C2011','D2010','E2001','F2005','F2009','G2003','G2007','H2004','H2010')
  sp1 &lt;- c(4,83,1,2,4,3,1,5,7,2,4)
  sp2 &lt;- c(5,0,2,3,10,5,0,2,4,3,1)
  sp3 &lt;- c(7,2,4,8,7,2,4,83,1,5,7)
  sp4 &lt;- c(0,2,4,2,4,12,1,5,7,2,4)
  Site &lt;- c('A','B','C','D','E','F','F','G','G','H','H')
  Year &lt;- c('2003','2010','2011','2010','2001','2005','2009','2003','2007','2004','2010')
  Obs &lt;- c(1,1,1,4,9,6,8,2,5,2,3)
  ID &lt;- c('A2003','B2010','C2011','D2010','E2001','F2005','F2009','G2003','G2007','H2004','H2010')
  df&lt;- data.frame(row.names, sp1, sp2, sp3, sp4, Site, Year, Obs, ID)
  rownames(df) &lt;- df[,1]
  df[,1] &lt;- NULL
  df
  #fix(df)
  df.1 &lt;- subset(df, Obs == 1)
  df.more &lt;- subset(df, Obs &gt;= 2)
  df.1
  df.more
  </code></pre>
  
  <p>And here it is the Script for the loop function in which I have problems:    </p>
  
  <pre><code>N.rows &lt;- nrow(df)
  for(i in 1:N.rows){      
    rnd.more &lt;- do.call( rbind, lapply( split(df.more, df.more$Site) ,
                                      function(df.more) df.more[sample(nrow(df.more), 1,replace=FALSE) , ] )  
    )
    print(rnd.more)
    rnd.df &lt;- rbind(df.1,rnd.more)                                   
    rnd.df.bc &lt;- as.matrix(vegdist(rnd.df[1:4], method="bray"))  
    clustering &lt;- agnes(rnd.df.bc, diss=TRUE, method = "ward")        
    print(clustering)
    grps.iter &lt;-cutree(as.hclust(clustering), k=3)                     
    print(grps.iter)
  }
  </code></pre>
  
  <p>Problems:</p>
  
  <p>1) The script is not working as I would like in its totality because the 'do.call' function gives me a data frame without keeping the row names. So for the following results I cannot identify my observations.</p>
  
  <p>2) I would like to save the output. If it is not possible doing it at once (they have different forms), maybe separately as "rnd.more", "clustering" and "grps.iter"</p>
  
  <p>I have tried looking into other questions/responses but I did not understand how to do it...</p>
  
  <p>Thanks for your help. Have mercy on me, I'm a self-learning R user... (and not so good!)</p>