Patnaik, Tirthankar wrote:
> Hi,
>       Quick question: Say I have a date variable in a data frame or
> matrix, and I'd like to preserve the date format when using write.table.
> However, when I export the data, I get the generic number underlying the
> date, not the date per se, and a number such as 11323, 11324, etc are
> not meaningful in Excel. Is there any way I can preserve the format of a
> date on writing into a text-file?
>
>   
Er, what is exactly the problem here?

> d <- data.frame(date=as.Date("2007-6-1")+1:5, x=rnorm(5))
> d
        date             x
1 2007-06-02  0.7987635130
2 2007-06-03 -0.7381623316
3 2007-06-04 -1.3626708691
4 2007-06-05  0.0007668082
5 2007-06-06  0.6719088533
> write.table(d)
"date" "x"
"1" 2007-06-02 0.798763513018864
"2" 2007-06-03 -0.738162331606612
"3" 2007-06-04 -1.36267086906438
"4" 2007-06-05 0.000766808196322155
"5" 2007-06-06 0.671908853312511
> write.csv(d)
"","date","x"
"1",2007-06-02,0.798763513018864
"2",2007-06-03,-0.738162331606612
"3",2007-06-04,-1.36267086906438
"4",2007-06-05,0.000766808196322155
"5",2007-06-06,0.671908853312511


-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED])                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch 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.

Reply via email to