0

In R, how do I convert the string 1/2010 (week 1 of 2010) into a Date or POSIXct (or POSIXlt) object?

I tried

as.Date('1/2010', "%W/%Y")
[1] "2010-06-29"

I also tried

strptime('1/2010', "%W/%Y")
[1] "2010-06-29 BRT"

But these are clearly not what I want.

In the end, I guess doesn't really matter which exact is picked, so long as I can correctly re-convert this to "weeks since origin".

djas
  • 973
  • 8
  • 24

1 Answers1

-1
library(splitstackshape)

date <- c("1/2013","3/2013")
date = data.frame(date)

df = data.frame(cSplit(date,"date","/"))

colnames(df) = c("week", "year")

df$date = as.Date(paste(df$year, df$week, 1, sep="-"), "%Y-%U-%u")
DemetriusRPaula
  • 377
  • 1
  • 10
  • @djas Hope it is what you need! – DemetriusRPaula Jun 29 '16 at 20:34
  • Please edit with more information. Code-only and "try this" answers are discouraged, because they contain no searchable content, and don't explain why someone should "try this". We make an effort here to be a resource for knowledge. – abarisone Jun 30 '16 at 06:17