title: Subset Data with the assign Function in R
body: <p>I'm new to programming in R (or at all), and I've been stuck on a problem for a few days. Apologies if this question already exists in some form, but I've looked as best I can and can't find anything.</p>
  
  <p>I have multiple datasets called pop1, pop2, pop3, etc. and I'm trying to assign a value of zero to a specified subset of them from within a for loop. Through trial and error, I've found that the code:</p>
  
  <pre><code>subset(get(paste("pop", 1, sep = "")), ind == 46, select = -ind)
  </code></pre>
  
  <p>returns the subset I'm looking for, but when I try:</p>
  
  <pre><code>for (i in 1:3) {
    assign(subset(get(paste("pop", i, sep = "")), ind == 46, select = -ind), 0)
  }
  </code></pre>
  
  <p>I get the error message:</p>
  
  <pre><code>#Error in assign(subset(get(paste("pop", i, sep = "")), ind == 46, select = -ind),  : 
    #invalid first argument
  </code></pre>
  
  <p>It seems to me that the assign function won't take subsets as its first argument, since none of the following work either:</p>
  
  <pre><code>assign(pop1[46, -1], 0)
  assign(pop1$trait1, 0)
  assign(subset(pop1, ind == 46), 0)
  </code></pre>
  
  <p>Is there a way I can make this work? Thanks very much, and let me know if more information would be helpful.</p>