[R] Using transform to add a date column to a dataframe

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Dec 23 17:14:50 CET 2008


Prof Brian Ripley wrote:

> 
> A Date object is not a vector.  In released versions of R, data.frame() 
> only knows how to replicate vectors and factors.

That's a rather oblique way of saying that it actually does work with 
the unreleased version:

 > head(transform(airquality,Date=as.Date("1950-01-01")))
   Ozone Solar.R Wind Temp Month Day       Date
1    41     190  7.4   67     5   1 1950-01-01
2    36     118  8.0   72     5   2 1950-01-01
3    12     149 12.6   74     5   3 1950-01-01
4    18     313 11.5   62     5   4 1950-01-01
5    NA      NA 14.3   56     5   5 1950-01-01
6    28      NA 14.9   66     5   6 1950-01-01
 > R.version.string
[1] "R version 2.9.0 Under development (unstable) (2008-12-23 r47310)"



-- 
    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
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list