0

I have a character vector in r that I obtained from a data.frame, which contains the dates of said data.frame. But there's an "x" at the beginning of each date. It looks like this (its just a part of the vector):

> dates_MODIS
  [1] "X2015.01.01" "X2015.01.17" "X2015.02.02"
  [4] "X2015.02.18" "X2015.03.06" "X2015.03.22"
  [7] "X2015.04.07" "X2015.04.23" "X2015.05.09"
 [10] "X2015.05.25" "X2015.06.10" "X2015.06.26"
...

I'm planning in converting this character vector into a date object, in order to use it in a new data.frame, but I can't convert it with as.Date() because of that "x" in the dates.

Any idea of how I can delete that "x" from every date, or another way of converting my character string into a date format?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213

1 Answers1

0

You can use :

dates_MODIS <- c("X2015.01.01", "X2015.01.17", "X2015.02.02")
dates_MODIS <- as.Date(dates_MODIS, 'X%Y.%m.%d')
dates_MODIS
#[1] "2015-01-01" "2015-01-17" "2015-02-02"
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213