-2

this is likely really simple, but I am unable to find the answer (probably not searching for the right thing...)

How can I insert a lead 0 into a column of numeric values...

Example:

values <- c(91414, 80113)

Such that they appear like this afterward:

091414, 080113

Then I would like to transform to a date, and I assume I would just:

date <- as.Date(values, format = "%m%d%y")

Any and all help appreciated...

gh0strider18
  • 155
  • 1
  • 8

1 Answers1

0

Try this, using the lubridate package for the date transformation:

X<-c(91414,80113)
X_date<-mdy(paste("0",as.character(X),sep=""))
X_date

[1] "2014-09-14 UTC" "2013-08-01 UTC"

This turns your numeric data to text and add a "0" to the the start of each value, then mdy does the date conversion.

John Paul
  • 12,196
  • 6
  • 55
  • 75