How to change repeat dates that occur right after each other

1 view (last 30 days)
I'm running into some issues with a dataset that I have. So basically, for some reason, the service I used to collect the data is changing some of the dates to be repeats. Here is an example of what I'm talking about
So you will notice in this example that the 9/15 date is missing and that the 9/16/19 date is repeating twice. And you would be right. Through diagnosing the issue, I learned that the first 9/16/19 date is actually supposed to be 9/15/19 and the subject didn't actually submit two prompts that day. This is a very characteristic pattern throughout the dataset where there are a few lines that repeat for whatever reason.
What I want to do is take the first 9/16/19 line and turn it into 9/15/19.
This is of course just an example, but there are many points in the dataset I've attached where this issue recurs. If someone knows a way to fix it using a loop to address all the data in the dataset, please let me know. It'd be very tedious to have to go through linebyline of all my datasets and figure out a fix. Thanks in advance
In the specific dataset I attached, you can see the issue on line 237/238 first, and the next recurrence is at line 249/250 in case you need some examples!

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 27 Jul 2022
Edited: Cris LaPierre on 27 Jul 2022
Perhaps not the most straightforward way, but this appears to work for me on your processed Nightly_Prompt.xlsx data. Basically, it finds any locations where the data is the same and replaces the date with the date immediately preceeding it. It then deletes the row immediately preceeding it.
ind = hours(diff(Night_Prompt.StudyDate))==0;
Night_Prompt.StudyDate([ind; false]) = Night_Prompt.StudyDate([ind(2:end); false; false]);
Night_Prompt([ind(2:end); false; false],:) = []
You could probably follow a similar approach with the raw data.
BA on 29 Jul 2022
Wow this is great. Thank you so much for your help! I can't thank you enough for doing this. Really really appreciate it!

Sign in to comment.

More Answers (0)


Find more on Tables in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!