-2
> date<-as.character(date)
> head(date)
[1] "14-Jan" "14-Jan" "14-Jan" "14-Jan" "14-Jan" "14-Jan"
> date1<-as.Date(date,format="%y-%b")
> head(date1)
[1] NA NA NA NA NA NA

I wanna convert the date into date format so that i can make a extensible time series data.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
user3566160
  • 21
  • 2
  • 5

1 Answers1

0

As Scott mentions, you may need to add the day value. Here is another way with paste (assumes the 1st day of the month for all entries):

date <- as.character(c("14-Jan", "14-Jan", "14-Jan", "14-Jan", "14-Jan", "14-Jan"))
date1 <- as.Date(paste0(date, "-1"),format="%y-%b-%d")
head(date1)
#[1] "2014-01-01" "2014-01-01" "2014-01-01" "2014-01-01" "2014-01-01" "2014-01-01"

you could then go back to displaying a year-month format in the following way:

format(date1, format="%y-%b")
#[1] "14-Jan" "14-Jan" "14-Jan" "14-Jan" "14-Jan" "14-Jan"
Marc in the box
  • 11,769
  • 4
  • 47
  • 97
  • You could use `substr` to cut out the day: `date1 <- substr(as.Date(paste0(date, "-1"),format="%y-%b-%d"),1,7)` – mrp Nov 11 '14 at 06:46