title: Update variable while reading in files in R loop
body: <p>I am reading multiple txt files and I would like to remove the first row and save it as a variable, transpose it and later when I'm done doing stuff I would like to save it along with other variables in a file. </p>
  
  <p>The problem is that my code is just saving the first txt information and repeating it for the rest of the txt files. </p>
  
  <p>My code: </p>
  
  <pre><code>    for(i in 1:length(filesW))
  {
    data &lt;- read.table(paste0("data",i,".txt", sep=""), sep=",", header=TRUE)
    winstepsdat2 &lt;- data.frame(data)
  
  
    genparameter&lt;-t((winstepsdat2[1,]))
    winstepsdat&lt;-winstepsdat2[-1,]
  
    num_col&lt;-ncol(winstepsdat)
    num_row&lt;-nrow(winstepsdat)
  
    colnames(winstepsdat) &lt;- paste("i", 1:num_col, sep="")
    winstepsdat$name&lt;- paste ("p", 1:num_row, sep="")
  
    #must change ni and labels for 1:n??
    cmd &lt;- wcmd(title = "R2Winsteps Example", data=paste0("data",i,".txt"),item1 = 1, ni =num_col , name1 = 30, namelen = 20,labels = paste('i',                                                                                                                                1:num_col, sep = ""), hlines = "Y" ) #codes=1:5
  
    write.wdat(winstepsdat, cmd)
  
    write.wcmd(cmd, paste0("CMFILE[",i,"].cmd"))
  
    winsteps2(cmd, outfile=paste0("outfile[",i,"].txt"), pfile=paste0("pfile",i,".txt"), ifile=paste0("ifile",i,".txt"), windir="C:/Winsteps/Winsteps.exe")
  
  } #end for
  </code></pre>
  
  <p>Somehow winstepsdat does change as I go through text files (given that I get different values for other calculations, but genparameter just keeps the first txt file values. How can I store/save genparameter for every text file I read?</p>
  
  <p>I'm a beginner programmer so I would appreciate the help. Thanks, Shmy</p>