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

Charilaos Skiadas cskiadas at gmail.com
Thu Nov 29 05:48:49 CET 2007


Allen,

what is the separator then? Can you give us a minimal example of a  
file? Otherwise we can't really help you much I'm afraid.
If you want spaces to count as NA, then you want to set na.strings="  
" probably, but read.table by default uses spaces to separate  
columns, so you will want to also set sep="...", where ... is what  
separates entries in your case. If your data is in fixed width  
format, then as Jim pointed out you should be using read.fwf instead.

Haris Skiadas
Department of Mathematics and Computer Science
Hanover College


On Nov 28, 2007, at 8:21 PM, affy snp 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?
>>



More information about the R-help mailing list