How to change repeat dates that occur right after each other

3 次查看(过去 30 天)
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
9/13/19
9/14/19
9/16/19
9/16/19
9/17/19
9/18/19
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!
  6 个评论

请先登录,再进行评论。

采纳的回答

Cris LaPierre
Cris LaPierre 2022-7-27
编辑:Cris LaPierre 2022-7-27
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.
  6 个评论
BA
BA 2022-7-29
Wow this is great. Thank you so much for your help! I can't thank you enough for doing this. Really really appreciate it!

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by