[R] Writing Vector to a File
Gundala Viswanath
gundalav at gmail.com
Mon Jun 23 15:15:53 CEST 2008
Dear Philipp and Duncan,
I've tried
> write(as.character(myvec), "output.txt", sep="\n")
and
> writeLines(as.character(myvec), "output.txt", sep="\n")
Both yielding same result.
>> 1
>> 1
>> 1
>> 1
>> 1
>> 6241
Is there any other possible explanation, why it
still went wrong?
- Gundala Viswanath
Jakarta - Indonesia
On Mon, Jun 23, 2008 at 8:02 PM, Philipp Pagel <p.pagel at wzw.tum.de> wrote:
>> 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
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list