Home > database >  Remove the end of string in R
Remove the end of string in R

Time:06-08

I actually have that:

a <- "Submitted 28 March, 2022;        originally announced March 2022." 

But I only want to have the date, so: "28 March, 2022" or that "Submitted 28 March, 2022"

Can you help me ?

Thanks in advance!

CodePudding user response:

You can use the parsedate package:

a <- "Submitted 28 March, 2022; originally announced March 2022."
parsedate::parse_date(a)
# "2022-03-28 UTC"

CodePudding user response:

You can do:

gsub(";.*", "", a)

"Submitted 28 March, 2022"

Or gsub("Submitted |;.*", "", a)

"28 March, 2022"

  • Related