I am trying to add single seconds to any repeated dates in my data frame.
i.e. from this:
value date
18 2013-07-09 16:49:23
62 2013-07-09 18:01:36
64 2013-07-09 18:46:51
29 2013-07-09 18:46:51
22 2013-07-09 18:46:51
....
I would like to obtain this:
value date
18 2013-07-09 16:49:23
62 2013-07-09 18:01:36
64 2013-07-09 18:46:51
29 2013-07-09 18:46:52
22 2013-07-09 18:46:53
....
I understand I can simply add + 1 or +2 to the POSIXct format to add seconds- however I don't know how to select the duplicates. Note that my dataframe is a few hundred of rows long, and a date can appear up to 20 times in a row.
I am thinking of doing something along these lines:
for (item in duplicated(dataframe$date)) {
if (item == TRUE) {
for (n in 1:#length of duplicated dates) {
dataframe[index(item) +n]$date <- (dataframe[index(item) +n]$date +n)
} } }
Thank you for your help!