[R] Conversion from string to date type

Andreas Tille tillea at rki.de
Fri Mar 23 23:23:05 CET 2007


On Fri, 23 Mar 2007, jim holtman wrote:

> Here is how you can convert them to a Date object:
>
>> x <- c('01.03.2007','02.03.2007','03.03.2007')
>> y <- as.Date(x, format="%d.%m.%Y")
>> y

Well, this is what I tried when reading the docs, but

> mydata <- read.csv(file='mydata.dat', sep = '\t', quote='', fill=TRUE,header=TRUE )
> datum <- as.Date(mydata["date"], "%d.%m,%y")
Error in as.Date.default(mydata["date"], "%d.%m,%y") :
         do not know how to convert 'mydata["date"]' to class "Date"

I also tried:

> datum <- strptime(imydata["date"], "%d.%m,%y")
> datum
[1] NA

I guess it is a very simple thing I'm doing wrong and missinterpret
the docs.

Thanks for the quick response

            Andreas.

-- 
http://fam-tille.de



More information about the R-help mailing list