[R] rewrite a data file use write.table(), count.fields() show different pattern, any suggestion appreciated.

Yong Wang wangyong1 at gmail.com
Tue May 22 14:04:22 CEST 2007


Dear all:

I read in a tab delimited dataset, and then write it out as another
file as following: I did this simply to make sure I understand the
behavior of this command.

data<-read.table(file,header=F,sep="\t",fill=T,colClasses="character");
write.table(data,file="newdata.txt",eol="\n",sep="\t",quote=F,row.names=F);


cf1 <- count.fields(newdata.txt, sep="\t")
table(cf1)
13   17       23
10   126   5445

# is different to

cf2 <- count.fields(file,sep="\t")
13   17       23        33
10   106   5433      32

the worst problem is the maximal value of cf1 (33) is larger than the
maximal value of cf2 (23) which is the right number of fields for most
rows in the original file.

I need to use write.table for some important data manipulation work,
your suggestion is
highly appreciated.

Best Regards



More information about the R-help mailing list