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
??????????????????????????
Claudia Beleites
2013-Mar-07 20:44 UTC
[R] Transpose a big data file and write to a new file
Hi Yao He, this doesn't sound like R to me. I'd go for perl (or awk). See e.g. here: http://stackoverflow.com/questions/1729824/transpose-a-file-in-bash HTH Claudia Am Wed, 6 Mar 2013 22:37:14 +0800 schrieb Yao He <yao.h.1988 at gmail.com>:> 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 > ?????????????????????????? > > ______________________________________________ > 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.-- Claudia Beleites Spectroscopy/Imaging Institute of Photonic Technology Albert-Einstein-Str. 9 07745 Jena Germany email: claudia.beleites at ipht-jena.de phone: +49 3641 206-133 fax: +49 2641 206-399