how can I separate data per group ID

2 visualizzazioni (ultimi 30 giorni)
Hello,
I have a csv data file containing a column with group ID (string), and a column with measured data .
(For each group, there are many measurements).
I want to separate & process the data per group, extracting & processing vector of measured data for each group
The problem is that the number of measurements per group is different for different groups, so I can not apply cycle.
Is it possible to separate data per group , by reading the group ID and creating data vector for each group ID ? Thank you !
  2 Commenti
Bhaskar R
Bhaskar R il 20 Gen 2020
Modificato: Bhaskar R il 20 Gen 2020
Can you share your file as a sample?
Stephen23
Stephen23 il 20 Gen 2020
"The problem is that the number of measurements per group is different for different groups, so I can not apply cycle."
I don't see any reaons why that would be the case, a simple loop with indexing would work fine, as would any of the more recent tools for handling groups of data:

Accedi per commentare.

Risposta accettata

Guillaume
Guillaume il 20 Gen 2020
Modificato: Guillaume il 20 Gen 2020
The fact that you don't have the same number of samples per group should not be a problem. As Stephen commented, this wouldn't prevent you from using a loop.
However, as Stephen also said, matlab has plenty of tools designed just for this sort of processing. The exact tool to use depends on what exactly you want to do, and you haven't said. It could be something as simple as:
measurements = readtable('C:\somewhere\yourfile.csv');
%I'm assuming your file has headers and one of them is ID
IDmean = groupsummary(measurement, 'ID', 'mean'); %get the mean of each signal per ID
  2 Commenti
Galina Machavariani
Galina Machavariani il 20 Gen 2020
Thank you very much, Guillaume
I earlier used "csvread " command, and did not know about "groupsummary"
I tried groupsummary, but here is what I obtain:
"Warning: Variable names were modified to make them valid MATLAB identifiers. The original names are saved in the VariableDescriptions property. "
How to overcome this ? Thanks !!!
Guillaume
Guillaume il 20 Gen 2020
This warning comes from readtable not from groupsummary. Additionally, it is just a warning, it may not be a problem. However, if you're on R2019b or later, you can get rid of it with:
measurements = readtable('yourfile', 'PreserveVariableNames', true);
In earlier versions, you can't do that. Best you can do is rename the variables to whatever you want if you don't like the names matlab autogenerate.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by