[R] For loop on data frame

Esam Tolba eatolba at gmail.com
Thu Jan 31 19:45:08 CET 2013


I am a beginner in R.
I wrote a function to read a data frame from a file and then split it
into certain number of data frames and write each one of them  in a
separate txt file.
the function is working perfectly for the first four files the it
gives me files contain one column of NA values.

split= function (filename,linesno,filesno) {
                        i=1
                        j=linesno
                        k=1
                        e=1
                        x=read.table(filename, sep=("\t"), header= FALSE)
                        for (i in 1:filesno){
                                xx=x[e:j, ]
                                l=paste0(filename,0,k,".pdb")
                                write.table(xx, l, quote =FALSE, sep =
"\t",row.names = FALSE, col.names = FALSE)
                                k=k+1
                                e=e+j
                                j=2*j
                                }
        }
what could be the problem?
Esam



More information about the R-help mailing list