Missing dates in a dataset and filling in for them.

조회 수: 20 (최근 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 CenterFile Exchange에서 Timetables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by