0

I'm new to R and I have tried the search function but couldn't make much sense of what I found.

I have a string like this: 20/08/2016

How can I convert it to 20/08/16

Any help is much appreciated.

Nckh
  • 67
  • 1
  • 6

1 Answers1

2

Maybe you can try something like below

s <- "20/08/2016"
format(as.Date(s,"%d/%m/%Y"),"%d/%m/%y")
# [1] "20/08/16"

or

gsub("(.*/)\\d{2}(.*)","\\1\\2",s)
# [1] "20/08/16"
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81