brunktier
brunktier

Reputation: 75

Conversion of numeric vector to date

I have a dataframe with a date column like the following:

19870703
19920929
20051015
20030613

How can I change the numeric Data to a Date format like %Y%m%d? Neither as.date() nor as.POSIX.ct() works?

Upvotes: 0

Views: 1178

Answers (3)

user2974951
user2974951

Reputation: 10385

library(date)
as.date(your.date.vector)

Upvotes: 0

Hunaidkhan
Hunaidkhan

Reputation: 1443

Using lubridate

date <- ymd("19870703")

in place of date you can put your column name

Upvotes: 2

Prakash Natarajan
Prakash Natarajan

Reputation: 138

as.Date("19870703", "%Y%m%d")
[1] "1987-07-03"

Apply for entire column.

Upvotes: 0

Related Questions