0

I have a date value stored as a string in the following format: (Day_of_week Month Day, Year). I would like to remove the day of the week so the final format is: (Month Day, Year)

mydata <- data.frame(Date=c("Tuesday, September 19, 2017",
                            "Friday, April 20,2018"),
                     Date_Exp=c("September 19, 2017",
                                "April 20,2018"))
divibisan
  • 11,659
  • 11
  • 40
  • 58
Yogesh Kumar
  • 609
  • 6
  • 22

3 Answers3

3

as @Wiktor Stribiżew said.. ur task is clear but couldnt get the purpose. However this could solve ur problem:

format(as.Date(mydata$Date,format = "%A, %B %d, %Y"), format="%B %d %Y")
[1] "September 19 2017" "April 20 2018" 
Akshay
  • 76
  • 4
0

Using gsub we can remove any number of characters followed by "," and space from the beginning of the date.

mydata$Date <- gsub("^[a-zA-z]+, ", "",mydata$Date)
A. Suliman
  • 12,923
  • 5
  • 24
  • 37
0

You could keep your dates as character strings and then use regex to remove the day of the week:

vec <- c("Tuesday, September 19, 2017", 
         "Friday, April 20,2018")

trimws(sub("^.*?,","",vec))

#[1] "September 19, 2017" "April 20,2018"    
divibisan
  • 11,659
  • 11
  • 40
  • 58
Andre Elrico
  • 10,956
  • 6
  • 50
  • 69