Missing dates in a dataset and filling in for them.

15 ビュー (過去 30 日間)
Claire Hollow
Claire Hollow 2020 年 5 月 29 日
コメント済み: Adam Danz 2020 年 5 月 29 日
Hello. I have a 2916x14 matrix of data that I have attached. Column 6 gives the date but my problem is that some random days are missing. I am looking to add in the missing dates and for columns 1-5, to use what was in the previous row (they are the same throughout the data) and to fill in 'NA' for columns 7-14 for all of the missing dates. I have tried to play around with retime and datetime but I am not having much luck and to be honest I don't know where to go from here. Any help would be greatly appreciated, thank you!m
  2 件のコメント
Adam Danz
Adam Danz 2020 年 5 月 29 日
Could you share what you tried with retime? That should solve most of the items on the list.
Claire Hollow
Claire Hollow 2020 年 5 月 29 日
I tried 'eustisretimes=retime(eustis48to55(:,6),'daily');' but I got an error because it is a table and not a timetable. Tried a few thigns to solve with no luck so far.

サインインしてコメントする。

回答 (1 件)

Adam Danz
Adam Danz 2020 年 5 月 29 日
Convert your table to a timetable.
Then use retime() to fill in missing dates on a daily basis. The columns will be filled with values from the previous row. See retime() for details.
Since the data in columns 7:end are all "NA", the NA values will be filled according to your description.
However, the last two lines show how to fill the new rows with NA values even though they are already NA.
TT = table2timetable(eustis48to55,'RowTimes','DATE');
TTr = retime(TT,'daily','previous');
% Find which rwos of TTr have been added.
missingIdx = ~ismember(TTr.DATE,TT.DATE);
TTr(missingIdx,7:end) = {categorical({'NA'})};
  1 件のコメント
Adam Danz
Adam Danz 2020 年 5 月 29 日
If you want to convert back to a table, use timetable2table() but I suggest you keep the timetable since they offer advantages when working with timeseries data.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTimetables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by