[R] Working with temporal data

Marc Schwartz marc_schwartz at comcast.net
Fri Feb 16 16:11:52 CET 2007


On Fri, 2007-02-16 at 14:32 +0000, Sérgio Nunes wrote:
> Hi again,
> 
> I'm still trying to read my data but I'm having some difficulties
> converting it to dates.
> My data file has lines and in each line a single date exists in the
> format >2007/02/16< (without the >,<). I've tried the following:
> 
> > d <- readLines("file.dat")
> > d
> [1] "2006/08/09" "2004/02/11" "2004/06/09" ...
> [2] ...
> 
> > d2 <- as.Date(d, format="%Y/%m/$d")

You have a typo above.  '$d' should be "%d":

d2 <- as.Date(d, format = "%Y/%m/%d")

> str(d2)
Class 'Date'  num [1:3] 13369 12459 12578

HTH,

Marc Schwartz

<snip>



More information about the R-help mailing list