title: Store or print results for 't.test' in for loop
body: <p>I am new to R and having a problem with printing the results of 'for' loop in R. Here is my code:</p>
  
  <pre><code>afile &lt;- read.table(file = 'data.txt', head =T)##Has three columns Lab, Store and Batch
  lab1 &lt;- afile$Lab[afile$Batch == 1]
  lab2 &lt;- afile$Lab[afile$Batch == 2]
  lab3 &lt;- afile$Lab[afile$Batch == 3]
  lab_list &lt;- list(lab1,lab2,lab3)
  for (i in 1:2){
      x=lab_list[[i]]
      y=lab_list[[i+1]]
      t.test(x,y,alternative='two.sided',conf.level=0.95)
   }
  </code></pre>
  
  <p>This code runs without any error but produces no output on screen. I tried taking results in a variable using 'assign' but that produces error:</p>
  
  <pre><code>for (i in 1:2){x=lab_list[[i]];y=lab_list[[i+1]];assign(paste(res,i,sep=''),t.test(x,y,alternative='two.sided',conf.level=0.95))}
  Warning messages:
  1: In assign(paste(res, i, sep = ""), t.test(x, y, alternative = "two.sided",  :
  only the first element is used as variable name
  2: In assign(paste(res, i, sep = ""), t.test(x, y, alternative = "two.sided",  :
  only the first element is used as variable name
  </code></pre>
  
  <p>Please help me on how can I perform t.test in loop and get their results i.e. print on screen or save in variable.</p>
  
  <p>AK</p>