0

I'm very new to R. I imported some csv data containing dates which got made into factors. Trying to make them into R dates but with no success. I've tried the code below.

> class(mydata$Date)
[1] "factor"
> as.Date(mydata$Date, format = "%Y-%m-%d")

Date still shows up as factors, what can be done? Dates are originally in the format of YYYY-MM-DD, example: 2015-05-08

uncool
  • 2,613
  • 7
  • 26
  • 55
  • 2
    Try coercing to character first - `as.Date(as.character(mydata$Date, format = "%Y-%m-%d"))`. – jbaums May 10 '15 at 21:13
  • 1
    I never encountered in such issue. `class(as.Date(factor("2015-05-08"), format = "%Y-%m-%d"))` works fine for me. – David Arenburg May 10 '15 at 21:21
  • 2
    Don't forget to actually assign the result to your data frame - i.e. `mydata$Date <- as.Date(mydata$Date, format = "%Y-%m-%d")`? To assist further, we'd probably need to see an example that reproduces your problem. – jbaums May 10 '15 at 21:28
  • I didn't actually assign it, thanks! – uncool May 11 '15 at 20:11

0 Answers0