[R] how to read in a txt file with some blanks

jim holtman jholtman at gmail.com
Thu Nov 29 04:12:15 CET 2007


The question is what do the 'blanks' mean?  I assume that they are
separating the variables since that is the default for read.table.

So what is the difference between:

1) "1 2"   one blank
2) "1  2"  two blanks
3) "1   2" three blanks
4)........

How are these different conditions supposed to be interpreted?  Now
you replace the blanks with commas and that might do it for you. This
would mean that "1  2" (which would be two variables where there are 2
blanks) would now be "1,,2"  which would be three variables.  So you
need to define what is supposed to happen in these cases.

On Nov 28, 2007 8:21 PM, affy snp <affysnp at gmail.com> wrote:
> Hi Jim,
>
> Thanks a lot! I would like the blanks to be read as NAs.
> I tried
>
> cgh<-read.table(file=" WM115A.txt",header = TRUE,fill = TRUE,na.strings =
> "NA")
>
> but the blanks were just filled by their flanking columns.
>
> Best,
>      Allen
>
>
>
>
> On Nov 28, 2007 7:42 PM, jim holtman <jholtman at gmail.com> wrote:
> > If the data is fixed field, then read.fwf.  Else blanks are normally
> > allowed delimiters.  How do you want to interprete blanks?  There are
> > number of ways, none of which you have specified.
> >
> >
> >
> >
> > On Nov 28, 2007 6:46 PM, affy snp < affysnp at gmail.com> wrote:
> > > Hi list,
> > > Is there a way to read in a txt file with some blanks? The ideal way
> could
> > > be to replace blanks with NAs.
> > >
> > > Thanks a lot!
> > >
> > > Allen
> > >
> >
> >
> >
> > >        [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > 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.
> > >
> >
> >
> >
> > --
> > Jim Holtman
> > Cincinnati, OH
> > +1 513 646 9390
> >
> > What is the problem you are trying to solve?
> >
>
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list