Re: [R] Writing Vector to a File

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Mon, 23 Jun 2008 06:56:14 -0400

Gundala Viswanath wrote:
> Dear experts,
>
> I try not to trouble the list again after this question.
>
> 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
> [15] --Control HBA1 HBA2 HBB PTGDS GAPDH UBC
> [22] --Control GAPDH TPT1 HUWE1 PRM1 CKM OPHN1
> [29] GAPDH ACTA1 PTGDS S100A8 EEF1A1 APOD CALM2
> [36] TPT1 TUBA1B MT2A PTPRO AL581768 TUBA1B FTL
> [43] --Control NM_001403 TUBA1B TNNC2 TUBA1B IGL@ --Control
> [50] TUBA1C IGKC AA809056 IGKC TTN GH1 HBG2
> [57] TUBA1C MB GH1 GH1 MT1X UBB GH1
> [64] IGL@ MBP VIM GH1 ACTB HBG2 TTR
> [71] GH1 --Control MYL2 CFL1 EEF1A1 RPL37A IGHG3
> [78] PIP --Control HBG1 KRT13 --Control PRM2 IGLJ3
> [85] APOA1 ALDOA NM_022646 IGHA1 GFAP PRH1 ALDOA
> [92] APOA1 SPARCL1 GNAS --Control GPX3 APOC3 TNP1
> [99] MT1P2 GNAS
>
> 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?

>

It looks as though myvec is a factor or some other special object, not a character vector. You could write as.character(myvec) to correct this. You should probably look at str(myvec) to find out what it really is. You may also want to use writeLines() instead of write().

Duncan Murdoch

> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> 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.
>



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. Received on Mon 23 Jun 2008 - 11:02:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 23 Jun 2008 - 12:31:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive