RE: [R] Reading ASCII files

From: Liaw, Andy <andy_liaw_at_merck.com>
Date: Fri 23 Jul 2004 - 22:28:56 EST


You can use fill=TRUE and na.string="" in read.table(). E.g.,

> try.dat <- read.table("clipboard", colClasses=rep("character", 6),

+                       header=TRUE, fill=TRUE, na.string="")

> try.dat

  X1st line ID description snp_id genotype
1  2nd line 10003          Low rs152240     <NA>
2  3rd line 10003     Moderate rs189011       TC
3  4th line 10004 Conservative rs152240       GC
4  5th line 10004          Bad rs154354     <NA>
5  6th line 10013          Bad rs152240     <NA>
6  7th line 10019 Conservative rs152240       AC

HTH,
Andy

> From: Cristian Pattaro
>
> Dear all,
> I need to read an ASCII file with diffent length lines.
>
> This is what is contained in the file gene.txt:
> 1st line ID description snp_id genotype
> 2nd line 10003 Low rs152240
> 3rd line 10003 Moderate rs189011 TC
> 4th line 10004 Conservative rs152240 GC
> 5th line 10004 Bad rs154354
> 6th line 10013 Bad rs152240
> 7th line 10019 Conservative rs152240 AC
> etc...
>
> This is what I would like to obtain in R:
> ID description snp_id genotype
> 10003 Low rs152240 NA
> 10003 Moderate rs189011 TC
> 10004 Conservative rs152240 GC
> 10004 Bad rs154354 NA
> 10013 Bad rs152240 NA
> 10019 Conservative rs152240 AC
>
> Read.table() doesn't work in these situations because of the
> irregular
> pattern of data. Have you got any suggestion?
> Thanks a lot!
> Cristian
>
> ===========================================
> Cristian Pattaro
> ===========================================
>
> Unit of Epidemiology & Medical Statistics
> Department of Medicine and Public Health
> University of Verona
> cristian@biometria.univr.it
> http://biometria.univr.it
> ===========================================
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jul 23 22:42:18 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:37:33 EST