Cenk
Cenk

Reputation: 325

R, defining factors as dates

I have a date frame like this:

> head(bist.getiri)
       DATE       RETURN
1  4.1.1988           NA
2  5.1.1988  0.026124819
3  6.1.1988  0.000000000
4  7.1.1988 -0.005657709
5  8.1.1988 -0.009957326
6 11.1.1988  0.010057471

Class of "DATES" is factor and class of "RETURN" is numeric.

As it is seen DATEs are not in straight order. I would like to define DATES as date. Can any one help me?

Upvotes: 0

Views: 60

Answers (1)

vrajs5
vrajs5

Reputation: 4126

Try this

bist.getiri$DATE <- as.Date(bist.getiri$DATE, format = '%d.%m.%Y')

or

library(lubridate)
bist.getiri$DATE <- dmy(bist.getiri$DATE)

Upvotes: 2

Related Questions