take averages of obvervations for each month

1 view (last 30 days)
suppose I have a table S
date income
1/1/2020 100
1/2/2020 20
I want to create a table T of mean of income at each month like
month income average
1/2020 50
2/2020 20
So is it that I first create
T.yyyyMM=datetime(S.date, 'InputFormat','MM/dd/yyyy', 'Format','yyyyMM');
then use
Does it make sense?

Accepted Answer

jonas on 5 Jul 2020
Edited: jonas on 5 Jul 2020
Try this instead
where T is a timetable
t = (datetime(2020,1,1):days(1):datetime(2021,1,1))';
income = 10+rand(numel(t),1).*4;
T = timetable(t,income)
T_Monthly = retime(T,'monthly','mean')

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!

Translated by