MATLAB Answers

aggregate data of a dataset

6 views (last 30 days)
Megan
Megan on 16 Feb 2020
Edited: Megan on 19 Feb 2020
Hi guys how can I aggregate data vom my dataset array?

  0 Comments

Sign in to comment.

Accepted Answer

Sindar
Sindar on 16 Feb 2020
check out splitapply. You may need to change the format of your data, but it does exactly what you want:
G = findgroups(ds.seats);
mean_dist = splitapply(@mean,ds.score,G);
Switching to tables is probably a good idea:
ds = readtable("datasetT.csv");

  17 Comments

Sindar
Sindar on 16 Feb 2020
Sorry, I haven't actually used fillmissing much, so I'm not sure what's up. Regardless, I realized removing rows with missing entries is probably better for your purpose:
ds=readtable('datasetT.xlsx');
clean_ds = rmmissing(ds);
G = findgroups(clean_ds.Seat);
mean_dist = splitapply(@mean,clean_ds.score,G);
Megan
Megan on 16 Feb 2020
That worked out well Thanks!!!
One last question: now I have two rows with mean values.
How can I know which row is which seat number?
Sindar
Sindar on 16 Feb 2020
Look at the second output from findgroups:
[G,G_seat] = findgroups(clean_ds.Seat);
At the end, you can make a summary table:
sum_table = table(G_seat,mean_dist)

Sign in to comment.

More Answers (0)

Sign in to answer this question.