Tell me please, I have a date and time

date

> head(date) [1] "31-10-2014" "31-10-2014" "31-10-2014" "31-10-2014" "31-10-2014" "31-10-2014" 

and time

 > head(time) [1] "01:35" "01:45" "01:50" "01:55" "02:00" "02:05" 

you need to remove the "separators" so that it happens

remove the date "-"

 > head(date) [1] "31102014" "31102014" "31102014" "31102014" "31102014" "31102014" 

in time to remove ":"

 > head(time) [1] "0135" "0145" "0150" "0155" "0200" "0205" 

as well as the time you need to add seconds just stupidly "00" at the end

 > head(time) [1] "013500" "014500" "015000" "015500" "020000" "020500" 
  • Replacing "-" with an empty string and ":" also with an empty string will definitely save you in the first part. - Vladimir Martyanov
  • replacement where? can you somehow more deployed something .. - mr.T September
  • Replace in line. I am not an R specialist, so I don’t know what's up with string functions. - Vladimir Martyanov
  • I am also not an expert because I need a more specific answer, preferably with a code - mr.T

1 answer 1

In this case, the easiest way to use gsub to replace with fixed=TRUE (if performance is important then you will win a little on this)

 date1="31-10-2014" microbenchmark::microbenchmark({gsub("-", "", date1 )}, {gsub("-", "", date1 ,fixed = T)}) Unit: microseconds expr min lq mean median uq max neval { gsub("-", "", date1) } 4.462 5.132 6.40839 5.355 5.8020 33.915 100 { gsub("-", "", date1, fixed = T) } 1.338 1.339 2.40999 1.785 2.0085 44.179 100 

To add a “00” at the end just use paste0

 time1="01:55" paste0(gsub(":", "", time1 ,fixed = T),"00")