Warm tip: This article is reproduced from stackoverflow.com, please click
dataframe date r string

Removing slashes from dates within a data.frame

发布于 2020-04-05 23:34:15

I have a series of dates within a data.frame of the form x <- data.frame(01/01/2009). I would like to change the series to be of the form 01012009. I have tried the gsub("//","" x) but it does not appear to work.

I would just like to remove the back forward slashes. Any help would be greatly appreciated.

Questioner
user2832896
Viewed
66
thelatemail 2014-06-03 08:37

You don't need to escape a forward slash (which is not what you are doing anyway), so this will work, e.g:

dat <- data.frame(dates=c("01/01/2009","02/01/2009"))
dat
#       dates
#1 01/01/2009
#2 02/01/2009

dat$dates <- gsub("/","",dat$dates)
dat
#     dates
#1 01012009
#2 02012009