[R] For loop on data frame
Jeff Newmiller
jdnewmil at dcn.davis.CA.us
Thu Jan 31 20:42:41 CET 2013
Your example is not reproducible. See http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
I would guess you have tabs at the ends of your lines in the input file. This is a fairly common problem when you muck with data in Excel.
To find these problems yourself, learn to examine the objects you create by executing the statements one-to-one and interspersing ?str calls and printing objects so you understand what the code is working with.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Esam Tolba <eatolba at gmail.com> wrote:
>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
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list