[R] Writing Vector to a File
murdoch at stats.uwo.ca
Mon Jun 23 12:56:14 CEST 2008
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
>  --Control --Control --Control --Control --Control HBA2 HBA1
>  HBA1 --Control HBB --Control HBB HBA1 MBP
>  --Control HBA1 HBA2 HBB PTGDS GAPDH UBC
>  --Control GAPDH TPT1 HUWE1 PRM1 CKM OPHN1
>  GAPDH ACTA1 PTGDS S100A8 EEF1A1 APOD CALM2
>  TPT1 TUBA1B MT2A PTPRO AL581768 TUBA1B FTL
>  --Control NM_001403 TUBA1B TNNC2 TUBA1B IGL@ --Control
>  TUBA1C IGKC AA809056 IGKC TTN GH1 HBG2
>  TUBA1C MB GH1 GH1 MT1X UBB GH1
>  IGL@ MBP VIM GH1 ACTB HBG2 TTR
>  GH1 --Control MYL2 CFL1 EEF1A1 RPL37A IGHG3
>  PIP --Control HBG1 KRT13 --Control PRM2 IGLJ3
>  APOA1 ALDOA NM_022646 IGHA1 GFAP PRH1 ALDOA
>  APOA1 SPARCL1 GNAS --Control GPX3 APOC3 TNP1
>  MT1P2 GNAS
> However using this command:
> write(myvec, "output.txt", sep="\n")
> I get this instead in my output.txt:
> 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().
> - Gundala Viswanath
> Jakarta - Indonesia
> R-help at r-project.org mailing list
> 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