[R] Writing Vector to a File

Philipp Pagel p.pagel at wzw.tum.de
Mon Jun 23 13:02:39 CEST 2008


> I want to print this vector into a file
> 
> > myvec
>   [1] --Control --Control --Control --Control --Control HBA2      HBA1
>   [8] HBA1      --Control HBB       --Control HBB       HBA1      MBP
[...]
> 
> However using this command:
> write(myvec, "output.txt", sep="\n")
> 
> I get this instead in my output.txt:
> 
> 1
> 1
> 1
> 1
> 1
> 6241
> 6240
> 6240
> 1
> 6242
> 1
> 6242
> 6240
> ....
> 
> What's wrong with my command above?

I think your vector is a factor and what ends up in your file is the
internal representation of the factor.  Try this instead:

write(as.character(myvec), "output.txt", sep="\n")

cu
	Philipp


-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel



More information about the R-help mailing list