Hi everyone, I am having trouble understanding where I went wrong with my
code. It seems to logically be "all there"  but the output says otherwise.
I know this is a bit long but I can't seem to find the errors so I would
appreciate your help :)

This is my program :

files<-Sys.glob("*.rescount.txt");length<-length(files);* #selecting all
files of a particular extension, saving in a list*
a<-1;
while(a<=length) *#going through every element of the list*
{
  df1<-read.table(files[a]);
  c.leng<-length(files[,1]);
  r.leng<-length(files[1,]); *#creating data frame for output with the same
dimensions as input*
  opdf<-data.frame(matrix(rep(NA,nrow(df1)*ncol(df1)),nrow=nrow(df1)));
  opdf[,1]<-df1[,1];
  opdf[1,]<-df1[1,]; *#copying the first row and first column so they have
the same headers*
  b<-2;
  while(b<=c.leng) *#working through each row of the input data frame*
  {
    c<-2;
    while(c<=r.leng) *#working through each row element of a particular
column*
    {
      n<-(df1[c][b,]);
      k<-1;
      while(k<=(n-1)) *#inner loop to go through a value of 'k' variable*
      {
        ... *#working with the code to generate a value*
        opdf[c][b,]<-sum; *#[1]*
        k<-k+1;
      }
      c<-c+1;
    }
    b<-b+1;
  }
  fname<-strsplit(files[a],".seq.ptseq.rescount.txt"); *#generating uniqe
file names based on the input file names*
  ext<-".zsc.txt";
  filename<-paste0(fname,ext);

write.table(opdf,file=filename,row.names=FALSE,col.names=FALSE,quote=FALSE,sep="\t");
  a<-a+1;

}

If the input data frame is supposed to be :

*NAME    V1      V2     V3*
*V1' *         10      12       45
*V2'  *          56      34       79
*V3'  *         34      67        87

The output data frame should be :
*NAME    V1      V2     V3*
*V1' *         x        y       z
*V2'  *        a         b       c
*V3'  *         n         p       q
(all the letters of the alphabet are various numbers generated by the
program and filled in in the line marked by #[1]

However my output file contains this:
"x"
"(name of input file)"

	[[alternative HTML version deleted]]

