[R] Transpose a big data file and write to a new file

Yao He yao.h.1988 at gmail.com
Wed Mar 6 15:37:14 CET 2013


Dear all:

I have a big data file of 60000 columns and 60000 rows like that:

AA AC AA AA .......AT
CC CC CT CT.......TC
..........................
.........................

I want to transpose it and the output is a new like that
AA CC ............
AC CC............
AA CT.............
AA CT.........
....................
....................
AT TC.............

The keypoint is  I can't read it into R by read.table() because the
data is too large,so I try that:
c<-file("silygenotype.txt","r")
geno_t<-list()
repeat{
  line<-readLines(c,n=1)
  if (length(line)==0)break  #end of file
  line<-unlist(strsplit(line,"\t"))
geno_t<-cbind(geno_t,line)
}
 write.table(geno_t,"xxx.txt")

It works but it is too slow ,how to optimize it???

Thank you

Yao He
—————————————————————————
Master candidate in 2rd year
Department of Animal genetics & breeding
Room 436,College of Animial Science&Technology,
China Agriculture University,Beijing,100193
E-mail: yao.h.1988 at gmail.com
——————————————————————————



More information about the R-help mailing list