title: Is there a way to assign a variable input in R?
body: <p>I'm wondering how to replace the &quot;x&quot; in the code each time the for loop completes an iteration with the newly created &quot;p_&quot; variable. The goal is to update the data frame and remove the sampled name each time the loop completes one iteration so as not to pick the same name more than once. Is there a way to dynamically input a variable into that line?</p>
  <p>New to R so bare with me ! Thanks!</p>
  <pre><code>setwd('/Users/Mike/Desktop/Random Coding Projects/Draft Simulator')
  
  # Load data of players available to draft
  df &lt;- read.csv('Players.csv')
  
  # Load in data for snake draft positions
  snake_pos &lt;- read.csv('snake positions.csv')
  
  # Ask the user for draft info input
  # num_drafters &lt;- readline(prompt='Enter the number of people participating in the draft: ')
  # num_drafters &lt;- as.integer(num_drafters)
  # num_rds &lt;- readline(prompt='Enter the number of rounds in the draft: ')
  # num_rds &lt;- as.integer(num_rds)
  # pick_pos &lt;- readline(prompt = 'Enter your draft position: ')
  # pick_pos &lt;- as.integer(pick_pos)
  
  # Explicitly Defining Draft Parameters
  num_drafters &lt;- 10
  num_rds &lt;- 15
  pick_pos &lt;- 2
  
  # Assign Picks to Teams
  t1_picks &lt;- snake_pos[1,]
  pick_nos &lt;- snake_pos[pick_pos,]
  t3_picks &lt;- snake_pos[3,]
  t4_picks &lt;- snake_pos[4,]
  t5_picks &lt;- snake_pos[5,]
  t6_picks &lt;- snake_pos[6,]
  t7_picks &lt;- snake_pos[7,]
  t8_picks &lt;- snake_pos[8,]
  t9_picks &lt;- snake_pos[9,]
  t10_picks &lt;- snake_pos[10,]
  
  # Defining team class
  base_team &lt;- list(pl1 = '', pl2 = '', pl3 = '', pl4 = '', pl5 = '', pl6 = '',
                    pl7 = '', pl8 = '', pl9 = '', pl10 = '', pl11 = '', pl12 = '',
                    pl13 = '', pl14 = '', pl15 = '')
  class(base_team) &lt;- 'team_template'
  
  # Creating Individual Pick Variables
  total_picks &lt;- num_drafters * num_rds
  pick_list &lt;- seq(1,total_picks,by=1)
  
  for(i in pick_list) {
    assign(paste0('p_',i),sample(df[1:5,3], 1, replace = FALSE, prob = NULL))
    df &lt;- df[!(df$PLAYER.NAME==x),]
  }
  </code></pre>